home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / fweb / fweb-1.40 / manual / fwebman.tex (.txt) < prev    next >
LaTeX Document  |  1993-10-29  |  404KB  |  7,489 lines

  1. % fwebman.tex:  --- USER'S MANUAL for FWEB ---
  2. % Version 1.30 (June 15, 1993)
  3. % If you want to get the user's manual, you can use the make file FWEB.mk
  4. % that is provided with FWEB. You simply say
  5. %    make -f FWEB.mk fwebman
  6. % NOTE: This will launch a 180 page job to the line printer! Try this out
  7. % first with 
  8. %    make -n -f FWEB.mk fwebman
  9. % to make sure it's going to do what you want.
  10. % In case you can't use the make file, here are more details about fwebman.tex
  11. % This file must be used with the files indexing.tex, indexmac.tex, and mx.sty,
  12. % which are needed for the index and are provided with the FWEB distribution.
  13. % When you say "tex fwebman", you will get the files fwebman.dvi and
  14. % also fwebman.idx. Printing fwebman.dvi produces the manual, including a
  15. % table of contents. The latter file is intended to be used with the
  16. % utility makeindex. Say "makeindex -s mx.sty -p any fwebman.idx"; you will get
  17. % the LaTeX file fwebman.ind, which can then be processed with LaTeX to
  18. % give the index for the users manual. The sequence of operations should be
  19. %    tex fwebman
  20. %    makeindex -s mx.sty -p any fwebman.idx
  21. %    (print fwebman.dvi)
  22. %    latex fwebman.ind
  23. %    (print fwebman.dvi)
  24. % This sequence is to avoid overwriting the dvi file, and ensures that
  25. % makeindex gets the appropriate page number from fwebman.log.  Again, the
  26. % provided make file handles all this automatically.
  27. \newif\iftypesetfwebmac
  28. % Appendix F is provided for typesetting the FWEB macro package fwebmac.web
  29. % directly into the manual; however, by default this appendix is turned
  30. % off.  To turn it on, remove the comment symbol from the next line:
  31. %\typesetfwebmactrue
  32. %            *    *    *
  33. \def\PAGESTART{8}
  34. \def\contentsfile{fwebman.cts}
  35. \input fmanmacs
  36. \Wbegin[]{article}{1em}{1em}{\contentsfile}{{\&}{\|}{\\}{\\}{\\}{\@}{\.}{\.}}
  37. \def\Wtitle{--- FWEB USER'S MANUAL ---}
  38. \doctitle{User Manual}
  39. \vskip 15pt plus 3pt minus 3pt
  40. \maxsctn{-1}{19}
  41. \section INTRODUCTION.[1.2]
  42. \parinserto{6}{4}{0.58}
  43. {{\ssbf FWEB} understands C, C{\ttitlefont ++}, Fortran--77, Fortran--90,
  44. Ratfor, and \TeX.} 
  45. This manual describes how to write programs in Knuth's ^^{Knuth, Donald}
  46. \.{WEB} system, ^^{\>{WEB}}
  47. as adapted and extended by J.~A. Krommes ^^:author!present: ^^{Krommes,
  48. John~A.} 
  49. to handle the programming languages of \Fortran\ (including both
  50. \Fortran--77 and \Fortran--90),
  51. \Ratfor, \C, \Cpp, and~\TeX.  We shall 
  52. call this new version \FWEB\ ^^:\>{FWEB}:
  53. when necessary, but generally we'll just refer to the \WEB\ system.  This
  54. adaptation is a substantial modification of S.~Levy's \C~version \.{CWEB}
  55. ^^{Levy, Silvio} ^^{\>{CWEB}}
  56. of \.{WEB}, which in turn was a complete rewrite in~\C\ of Knuth's original
  57. \Pascal\ source. (\TeX~is written in the
  58. original \Pascal\ \WEB.)  The principal design contributions to this
  59. version of~\WEB\ are (1)~the concept of a current
  60. \It{language}, so that one can process code written in multiple languages
  61. in the same \.{WEB} run; (2)~new production rules for
  62. \Fortran, \Ratfor, and~\TeX\ (and some modifications of Levy's rules for~\C);  (3)~a
  63. \hbox{\C-like} built-in macro preprocessor; and (4)~the ability to directly
  64. translate \Ratfor\ into \Fortran. In addition, many miscellaneous details
  65. have been changed and a variety of convenience features have been added.
  66. For example, a general style-file mechanism allows the user to customize
  67. various actions of the system.
  68. This manual covers quite a breadth of material, from the most introductory
  69. to very advanced. To help identify the level of difficulty, the sections
  70. are marked with~0, 1, or~2 dangerous bends (here shown as \dbend) a~la the
  71. \TeX book. 
  72. \subsection Previous authors, and the structure of this manual.
  73. The \WEB\ system and this manual have evolved through contributions of
  74. several authors, principally Knuth and Levy, 
  75. ^^{Knuth, Donald} ^^{Levy, Silvio} ^^:author!previous:
  76. and the flavor of the system
  77. is best captured with those authors' original words. Levy attempted to
  78. highlight Knuth's original text by indenting it. Quoting from Levy's
  79. manual, ``The bulk of this document \bdots\ consists of quotes from Knuth's
  80. memo `The \.{WEB} System of Structured Documentation'; these quotes are
  81. clearly distinguished by their indentation, and apart from \[such
  82. substitutions as `code' for `Pascal'\], all other changes to them are
  83. explicitly indicated. This also serves to indicate which commands and
  84. features are common to all versions of \WEB\ and which are characteristic
  85. of this version (of course if you're new to \WEB\ you don't have to worry
  86. about this).'' In practice, new users of \WEB\ seem to find the indented
  87. style somewhat confusing; furthermore, the length of this manual has grown
  88. to a point where more than 50\% of the text is new.
  89. Therefore, in an attempt to accomodate everyone,
  90. this user manual can be \TeX ed in two ways, depending on the setting of
  91. the \TeX\ macro \.{\\ifbilevel}, ^^:\CS{ifbilevel}:
  92. defined near the beginning of the macro package \.{fmanmacs.tex} for this
  93. manual.  By default, that switch is false and most
  94. indentation is suppressed. (A few of the most significant quotes are
  95. indented in both formats.)  To obtain the indented style, say
  96. \.{\\bileveltrue}. ^^:\CS{bileveltrue}:
  97. In the bilevel mode, we shall preface Levy's remarks by
  98. ``{\bileveltrue \Levy:}'', and we shall feel free to interject additional
  99. remarks by enclosing them in square brackets or to skip extraneous material
  100. by using an ellipsis. The brackets and ellipses are also suppressed
  101. when the \.{bilevel} switch is false.
  102. \subsection The origins of \FWEB. ^^{\>{FWEB}!origins of}
  103. \It{(The contents of this subsection are totally irrelevant to the narrow
  104. goal of learning to use \FWEB.  But they might be of some ``cultural''
  105. interest.)}
  106. \FWEB\ was born of necessity.  One of the focuses of my research in
  107. theoretical plasma physics has been the construction and solution of
  108. so-called ``statistical closure approximations,'' the most famous example
  109. of which is Kraichnan's 1959 direct-interaction approximation~(DIA). 
  110. ^^{direct-interaction approximation}
  111. At some point around 1985 I decided that further progress would benefit
  112. greatly from numerical solutions of the DIA and related closures applied
  113. specifically to plasma turbulence.  (Kraichnan, Herring, and others had
  114. long before done the analogous calculations for neutral-fluid turbulence.)
  115. So I began writing my \.{DIA} code---in standard \Fortran.  The result was a
  116. disaster.
  117. I needed extensive memory allocation facilities, but \Fortran--77 doesn't
  118. provide them.  I simulated them using tricky array manipulations, but the code
  119. was difficult to debug and to understand. I wanted complicated data
  120. structures, but again \Fortran--77 wasn't up to the task.  
  121. ^^{language!Fortran:\FORTRAN!inadequacy of}
  122. Ditto for simple
  123. string manipulations, communication with the command line, and transparent,
  124. easy-to-write I/O statements.  In other words, I didn't want \Fortran--77
  125. at all; I wanted~C!\ \  So I threw away a year's worth of work and started
  126. over.
  127. The second time around, I at least had a better sense of the scale of the
  128. project---it was large.  Also, upon looking
  129. back at my original attempt, I realized that I couldn't understand the code
  130. at all, even though I had been fairly liberal with \Fortran-style comments.
  131. Looking ahead, I also realized that graduate students would likely become
  132. involved.  Since I have strong feelings about wanting my students to
  133. actually do physics instead of just computing, it became imperative to
  134. write the code using the most powerful documentation scheme available so
  135. they could quickly understand how it worked and could modify it as easily
  136. as possible.  Knuth's article on ``Literate programming''\cite{Knuth} had
  137. already provided a ``religious experience'' 
  138. ^^{religion}
  139. for me when I read it several years
  140. previously, tempered only by the fact that I hadn't been in a computing
  141. phase at that time.  But faced with the demands of the \.{DIA} project,
  142. Knuth's excellent points all came back and I realized that \WEB\ was the
  143. natural choice.  Luckily, Levy had just announced his beautiful \CWEB, 
  144. ^^{Levy, Silvio}
  145. so everything seemed to be in place.
  146. Then, another setback.  One of the important characteristics of plasma, as
  147. opposed to incompressible fluid, turbulence is the presence of linearly
  148. propagating waves---described most naturally with complex numbers.
  149. Unfortunately, C~doesn't have an intrinsic \&{complex} type.  \Cpp\ can
  150. easily be taught complex arithmetic,
  151. but good \Cpp\ compilers weren't widely available, especially on the Cray
  152. supercomputers on which I intended to work.  One can, of course, easily
  153. \&{typedef} a C~structure that duplicates \Fortran's layout of a complex
  154. number, but short of function calls one can't in~C perform arithmetic on
  155. complex structures in the natural way one does in \Fortran.  Readability
  156. was important.  So was vectorization, which also wasn't available in the
  157. C~compilers available at that time and in any case would probably be broken
  158. by function calls.  So reluctantly I decided that the
  159. innermost, computational routines of the code should be written in
  160. \Fortran.  
  161. Of course, no way was \CWEB\ going to handle \Fortran\ code gracefully.
  162. But my colleague Henry Greenside
  163. ^^{Greenside, Henry}
  164. had been arguing strongly for the use of
  165. \Ratfor\ as a superior tool, given that one was stuck with some sort of
  166. \Fortran.  I agreed, and also hoped that \Ratfor's C-like syntax would be
  167. close enough to C's that \CWEB\ would be adequate.  And so I plunged ahead,
  168. writing in a mixture of~C and \Ratfor.
  169. \CWEB\ worked for \Ratfor---sort of.  One was able to obtain the invaluable
  170. index, and often the \Ratfor\ routines typeset just fine.
  171. But there were constant annoying
  172. glitches because of the inevitable differences of syntax.  After a few
  173. years of experience, it became clear that one really wanted a proper
  174. \Fortran\ version of \WEB.   Also, the
  175. absence of a \Fortran\ macro preprocessor was causing us major annoyance.
  176. Although Knuth's original \WEB\ had a rudimentary preprocessor, Levy had
  177. deleted it for \CWEB, since C~has its own preprocessor.  
  178. I decided there needed to be one built in that would serve all languages
  179. equally well.  Thus, the major design goals were clear:  a new \Fortran\
  180. \WEB\ that also supported \Ratfor\ and~C, with a macro preprocessor. 
  181. So I learned how Knuth and Levy had implemented
  182. the syntax production rules, sat down with a \Fortran\ reference manual,
  183. and began to write some \Fortran\ productions.  I thought this would take a
  184. couple of weeks.  That was actually about right. Ultimately, however, my
  185. estimate of the total amount of
  186. work involved in realizing all of my ideas about an ``industrial strength''
  187. \WEB\ easily usable in the scientific environment was off by
  188. at least two orders of magnitude. (Well, I'm a \It{theoretical} physicist.)
  189. Some years later, I'm still upgrading \FWEB.  Had I been left to my own
  190. devices, I probably would never have made it publicly available, since the
  191. conflicts between trying to complete the research I had
  192. intended to do and maintaining a reasonable robust code are almost
  193. overwhelming.  But my colleague Charles Karney,
  194. ^^{Karney, Charles}
  195. a true expert both in \TeX\
  196. and scientific computation, began distributing codes written in \FWEB\ and
  197. convinced me that a public announcement was the best way of both achieving
  198. some sort of standardization and accomplishing the debugging task.  So an
  199. announcement was timidly made, and the response has been amazing.  Most
  200. incredible has been the continuing patience of the many users who are faced
  201. with a utility that is still not bug-free and that they might have
  202. designed differently.  \FWEB\ is far from perfect, but it's much better
  203. than my original attempt because of the many well-thought-out suggestions
  204. and questions that I continue to receive.  My profound thanks.
  205. (Incidently, in the midst of all this a workable version of the \.{DIA}
  206. code was finally finished with the completion of John Bowman's Ph.D.
  207. thesis\cite{Bowman} 
  208. ^^{Bowman, John}
  209. at Princeton University.  To John fell the terrible task of working with
  210. the early prototypes of \FWEB.
  211. The demands of his project stressed the system to its limits, sometimes
  212. beyond, and elaborate kludges were sometimes necessary in order for him to
  213. continue in a timely way with his research.  But John's excellent, properly
  214. skeptical remarks also measurable improved \FWEB, and in the final analysis
  215. it's still not clear to me that we could have accomplished so much in a
  216. period of just a few years had we not had the principles of \WEB\ and
  217. literate programming to help and guide us.  So I'll both apologize to John
  218. for the early days as well as thank him for his patience and valuable
  219. suggestions.  Although it's not uncommon for recent Ph.D.'s to want never
  220. to think about the thesis research again, I hope John will be an exception,
  221. since his contributions to both physics and \FWEB\ have been outstanding.
  222. \subsection Why is this {\tt *!@\%*\#@!} manual so large?.
  223. As stated above, \FWEB\ evolved from the excellent, tidy \CWEB\ code of
  224. Levy and Knuth.  Without \CWEB\ and Knuth's original \WEB, there would be
  225. no \FWEB, so my debt to those authors is very large indeed.  So I attempted
  226. to retain the original manual that came with \CWEB, adding to it as
  227. necessary.  That worked in the beginning, but as various features were
  228. added and, in particular, as I continued to try to explain \WEB\
  229. programming to a scientific user community that was strongly oriented
  230. toward vanilla \Fortran, the manual accreted very much new material---too
  231. much for the present organization.
  232. From at least two points of view, it is time for a complete rewriting of
  233. the manual.  First, the appearance of Knuth's new book\cite{Knuth} on {\sl
  234. Literate Programming} means that much background material can be omitted
  235. from the manual.  Second, I'm probably past the experimental stage of
  236. \FWEB; the functional design has mostly stabilized and I've accumulated
  237. enough experience to know where the troublesome points are.  So there's
  238. just the issue of time to worry about.  Unfortunately, that's nontrivial,
  239. so for now one is stuck with the present monstrosity.
  240. However, the size and detail of this manual are alleviated in two ways.
  241. First, Marcus Speh\cite{Speh}
  242. ^^{Speh, Marcus}
  243. moderates an \FWEB\ literate programming question and 
  244. answer bulletin board and information service, from which elementary
  245. information can be easily obtained.  Second, some of the appendices to this
  246. manual can be printed separately as a self-contained user guide.  Third,
  247. \.{emacs} users can obtain online help from an \.{fweb.info} file that is
  248. distributed with the \FWEB\ release.
  249. \section The PHILOSOPHY of \WEB.[2.6] ^^(\>{WEB}!philosophy(
  250. \parinserto{1}{5}{0.55}
  251. ``The {\ssbf WEB} system consists of two processors,
  252. {\ssbf WEAVE} and {\ssbf TANGLE}.  These are {\bfit software tools}...''
  253. The \WEB\ system consists of two processors, \WEAVE\ and \TANGLE. 
  254. ^^[\>{WEAVE}] ^^[\>{TANGLE}]
  255. These are \It{^:software tools:} in the sense of \KP\cite{KP}.
  256. ^^{Kernighan, B.} ^^{Plauger, P.}
  257. Together, these processors make important
  258. contributions to the two principle facets of software design: how to
  259. efficiently write a program that works and that can be easily maintained
  260. (\TANGLE); and how to document what you have done so that both you and
  261. others can understand, appreciate, and later modify the code (\WEAVE).
  262. \subsection The purpose of the processors. ^^(TeX:\TEX!need for(
  263. If one is not interested in obtaining documentation, the \TANGLE\ processor
  264. can be used stand-alone, as a powerful preprocessor for any of the source
  265. languages.  The \WEAVE\ processor must be used in conjunction with \TeX\ in
  266. order to obtain the documentation. Here documentation refers both to prose
  267. exposition of the logic and algorithms of the code, as well as to a typeset
  268. listing of the code itself.  Note that, strictly speaking, you don't
  269. actually have to know \TeX\ in order to document your code with \WEAVE.
  270. Just typing straight text at the appropriate places will produce
  271. documentation whose quality will be far in excess of what can be achieved
  272. with comment lines embedded in the source code. The code itself is typeset
  273. automatically in a visually appealing format by using special \TeX\ macros
  274. about which the user need not generally be concerned.  However, the more
  275. features of \TeX\ you employ, ^^{features!employing \TEX}
  276. the higher quality your documentation will
  277. be.  This is particularly important when the algorithms you are explaining
  278. are based on complicated mathematical formulas. The ability to typeset
  279. intricate mathematics right next to the code that implements the algorithm
  280. (or even as a comment \It{within} a line of source code), instead of trying
  281. to spell out the symbols in words in a series of comment lines, is so
  282. extraordinarily useful that it becomes difficult to understand how one
  283. could ever have gotten along without it.  Compare, for example, the
  284. standard Fortran commenting style
  285. {\codemode
  286. C Perform the integral over v parallel from alpha to beta of the Maxwellian:
  287. \Tab call integrate(x,alpha,beta,fM)
  288. \noindent with what \FWEAVE\ can achieve:
  289. \WP\7
  290. \&{call} $\\{integrate}(\|x,\alpha,\beta,f_M)$\5
  291. \Wc{ Perform $\int_{\alpha}^{\beta}\!dv_\parallel\,f_{\rm M}(v_\parallel).$ }
  292. \noindent Here one needs to know something about \TeX\ (not very much) in
  293. order to use math mode in the text of the comment; however, the typesetting
  294. of the equation itself was performed automatically. (If you want to know
  295. precisely how this was done, read about ``Overloading identifiers'' below.)
  296. Time spent learning the fundamentals of
  297. \TeX\ will be amply repaid in dramatically increased ^{productivity}---and
  298. it's not hard to learn to do even rather powerful operations.
  299. ^^)TeX:\TEX!need for)
  300. \subsection Top-down programming and structured design.
  301. \parinserto{2}{6}{0.6}
  302. ``The fundamental logic of the {\ssbf WEB} system encourages `top-down'
  303. programming and `structured' design.''
  304. The fundamental logic of the \WEB\ system encourages ``top-down''
  305. programming and ``structured'' design. 
  306. ^^:design, structured: ^^:programming!top-down: 
  307. Quoting from \KP, ``Top-down design
  308. and successive refinement attack a programming task by specifying it in the
  309. most general terms, then expanding these into more and more specific and
  310. detailed actions, until the whole program is complete.  Structured design
  311. is the process of controlling the overall design of a system or program so
  312. the pieces fit together neatly, yet remain sufficiently decoupled that they
  313. may be independently modified. \dots\ Each of these disciplines can
  314. materially improve programmer productivity and the quality of code
  315. produced.'' The \WEB\ system encourages you to work top-down by giving you
  316. the ability
  317. to break up your code into independent segments (called ``\It{^{modules}}'').
  318. Often, modules correspond to individual subroutines.  However, this is not
  319. necessary and the \WEB\ system goes further by strongly encouraging you to
  320. also subdivide long subroutines into additional modules that can be given
  321. names for readability, put into a separate place, and explained as logic
  322. dictates. \WEAVE\ prints out your explanations (and associated code
  323. fragments) in the \It{logical} order in which you have decided to explain
  324. the code.
  325. \TANGLE\ strips off the explanations and rearranges the code into the
  326. \It{physical} order in which the compiler should see it. For example, in
  327. \Fortran\ all \&{common} declarations ^^{declarations!\<{common}}
  328. must physically be placed at the beginning of a subroutine, before
  329. executable code. However, various parts of such declarations may be quite
  330. unrelated, and should logically be explained in separate, not necessarily
  331. adjacent, sections of the documentation. As another example, in C~code
  332. function prototypes should appear at the beginning if they are to be
  333. useful; however, it's distracting to find a very long list of prototypes at
  334. the beginning of the documentation.  \WEB\ allows one to both place
  335. the prototypes at the end of the documentation and to tell the compiler to
  336. read them first.  Finally, it might be desirable to explain the output
  337. routines of a code before the input routines, since one might then better
  338. know exactly what should be input.
  339. Though top-down programming is easy with \WEB, bottom-up coding is not
  340. excluded either.  It's perfectly possible to write very low-level routines
  341. first, if that's convenient, and hook them into the web. The flexibility to
  342. mix top-down and bottom-up programming in a superior documentation
  343. environment means that one gets the best of all possible worlds!
  344. \comment 
  345. {\ninerm
  346. The process is
  347. something like pigeon-holing mail, or filing records in a banking system.
  348. Assume that the bank must eventually process all the records for a certain
  349. month by customer number, and assume that as the data comes into the bank
  350. (with transactions of various customers randomly interspersed)
  351. it will be alphabetized by customer name in order of receipt. The
  352. alphabetical order and the numerical order of the records need not be the
  353. same.  We shall equate ``customer name'' with ``module name,''
  354. ``order of receipt'' with ``logical order'' (order of receipt of ideas),
  355. and ``numerical order'' with ``physical order.''  Filing the records into the
  356. appropriate  
  357. customer bins (modules) is the function of (the phase-one pass of) the
  358. \WEB\ system. After all records have been properly filed, a second phase
  359. processes them.  Phase two of \TANGLE\ processes each bin in  ascending
  360. numerical order. Phase two of \WEAVE\ prints a summary of all transactions
  361. of all customers, identified in the output by both name and number,
  362. \It{in the order that they were originally received}. (The customer might
  363. desire a printout of just his bin, but this microscopic view is not what
  364. \WEAVE\ provides directly. Rather, \WEAVE\ provides a \It{macroscopic}
  365. perspective of all the transactions so the bank can see when and how they
  366. all fit together.)  For good measure, phase three of \WEAVE\ produces a
  367. complete index and cross-reference of all the transactions [so that, in
  368. fact, the transactions of a particular customer (module) can be readily
  369. identified].
  370. \endcomment
  371. Although \WEB\ is simple in conception, it is quite sophisticated in
  372. practice because \WEAVE\ uses the full power of \TeX\ to typeset not only
  373. the expository documentation but also the actual code.  (Note that
  374. automatically formatting source code is nontrivial, because
  375. \WEAVE\ must understand a good deal about the language syntax in order to
  376. emphasize keywords, indent loops, and so forth.)  Such visual enhancements
  377. help one to write good code, because it can be
  378. more clearly and logically explained and, therefore, better understood in
  379. the future. 
  380. \parinsert{4}{7}{0.65}
  381. {``When arbitrary choices of syntax have arisen, the design of \FWEB\ has
  382. been strongly influenced by the solution adopted by the ANSI standard
  383. for~C.''}
  384. Furthermore, the \FWEB\ version of the \WEB\ system goes significantly
  385. beyond this. In 
  386. fact, \FTANGLE\ is also a \It{macro preprocessor} ^^{macro!preprocessing}
  387. and a \It{statement translator}. ^^{statement!translation}
  388. By allowing symbolic macro abbreviations for commonly used
  389. constructions, \FTANGLE\ allows you to write significantly more concise and
  390. therefore more readable code. Furthermore, in its \Ratfor\ mode
  391. ^^{Ratfor:\RATFOR} 
  392. it endows
  393. the \Fortran\ language with a richer, C-like syntax that provides much more
  394. logical, flexible, and readable loop and conditional constructions. These
  395. constructions are translated directly into
  396. \Fortran\  code. Although it is impossible to fully correct for the many
  397. design deficiencies of \Fortran\ (except by writing in a better language
  398. such as~C, which is highly recommended whenever possible), in many
  399. situations the 
  400. \Ratfor\  syntax is so close to that of the C~language that users have
  401. complained that they can't remember in which language they're programming.
  402. \FWEB\ deliberately adopts the point of
  403. view that the language syntaxes should be as close as possible because it
  404. is a common practice to mix languages, and uniform syntax should reduce the
  405. frequency of errors.  When arbitrary choices of syntax have arisen, the
  406. design of
  407. \FWEB\  has been strongly influenced by the solution adopted by
  408. the recent ANSI standard for~C. ^^{language!C!ANSI standard for}
  409. For example, the macro preprocessor behaves like C's, not like \.{m4} or
  410. Knuth's original preprocessor for his Pascal \WEB.
  411. \subsection Knuth's original description of \WEB.
  412. We begin with Knuth's original description of \WEB.
  413. \KNUTH
  414. ``The ^[philosophy] behind \.{WEB} is
  415. that an experienced system programmer, who wants to provide the best
  416. possible documentation of his or her software products, needs two things
  417. simultaneously:  a language like \TeX\ for formatting, 
  418. ^^{language!formatting} ^^{language!TeX:\TEX}
  419. and a language like~\[\C\]\  for programming.
  420. ^^{language!programming} ^^{language!C}
  421. Neither type of language can provide the best
  422. documentation by itself; but when both are appropriately combined, we
  423. obtain a system that is much more useful than either language separately.
  424. ``The structure of a software program ^^{software program!structure of}
  425. may be thought of as a ``^:web:'' that
  426. is made up of many interconnected pieces. To document such a program, we
  427. want to explain each individual part of the web and how it relates to its
  428. neighbors. The typographic tools provided by \TeX\ give us an opportunity
  429. to explain the local structure of each part by making that structure
  430. visible, and the programming tools provided by \[languages such as~\C\ or
  431. \Fortran\]  make it possible for us to specify the algorithms formally and
  432. unambiguously. By combining the two, we can develop a style of programming
  433. that maximizes our ability to perceive the structure of a complex piece of
  434. software, and at the same time the documented programs can be mechanically
  435. translated into a working software system that matches the documentation.
  436. \parinsert{5}{7}{0.5}
  437. ``The structure of a software program may be thought of as a `web' that
  438. is made up of many interconnected pieces.''
  439. ``Since \.{WEB} is an experimental system developed for internal use within
  440. the \TeX\ project at Stanford, this report is rather terse, and it assumes
  441. that the reader is an experienced programmer who is highly motivated to
  442. read a detailed description of \.{WEB}'s rules. Furthermore, even if a less
  443. terse manual were to be written, the reader would have to be warned in
  444. advance that \.{WEB} is not for beginners and it never will be: The user of
  445. \.{WEB} must be familiar with both \TeX\ and \[the source language in which
  446. he is writing\]. When one writes a \.{WEB} description of a software
  447. system, it is possible to make mistakes by breaking the rules of \.{WEB}
  448. and/or the rules of \TeX\ and/or the rules of \[the source language\].
  449. ^^{rules!breaking the}
  450. In practice, all three types of errors will occur, and you will get different
  451. error messages from the different language processors. In compensation for
  452. the sophisticated expertise needed to cope with such a variety of
  453. languages, however, experience has shown that reliable software can be
  454. created quite rapidly by working entirely in
  455. \.{WEB} from the beginning; and the documentation of such programs seems
  456. to be better than the documentation obtained by any other known method.
  457. Thus, \.{WEB} users need to be highly qualified, but they can get some
  458. satisfaction and perhaps even a special feeling of accomplishment when
  459. they have successfully created a software system with this method.''
  460. \endKnuth
  461. \subsection How to use \WEB.
  462. \Knuth ^^[\>{WEB}!using]
  463. \parinserto{3}{4}{0.55}
  464. Extensive cross-index information is gathered automatically.
  465. To use \.{WEB}, you prepare a file called \.{COB.WEB} (say), and then you
  466. apply a system program called \.{WEAVE} to this file, obtaining an output
  467. file called \.{COB.TEX}.  When \TeX\ processes \.{COB.TEX}, your output
  468. will be a ``pretty printed'' version of \.{COB.WEB} that takes appropriate
  469. care of typographic details like page layout and the use of indentation,
  470. italics, boldface, etc.; this output will contain extensive cross-index
  471. information that is gathered automatically. You can also submit the same
  472. file \.{COB.WEB} to another system program called \.{TANGLE}, which will
  473. produce \[for example\], a file \.{COB.FOR} that contains the \Fortran\ code
  474. of your \.{COB} program. The \Fortran\ compiler will convert \.{COB.FOR}
  475. into machine-language instructions corresponding to the algorithms that
  476. were so nicely formatted by \.{WEAVE} and \TeX. Finally, you can (and
  477. should) delete the files \.{COB.TEX} and \.{COB.FOR}, because \.{COB.WEB}
  478. contains the definitive source code. \[{\bf Are you paying attention? Did
  479. you hear what I just said?}\] Examples of the behavior of \.{WEAVE} and
  480. \.{TANGLE} are appended to this manual.
  481. \endKnuth
  482. When you are using \FWEB\ you should use the commands
  483. \.{FWEAVE} and \.{FTANGLE}
  484. ^^{\>{FWEAVE}} ^^{\>{FTANGLE}} ^^{\>{FWEB}!using}
  485. to avoid confusion with the original Pascal
  486. \WEB\ processors \WEAVE\ and \TANGLE, which are still supplied with the
  487. \TeX\ distribution. 
  488. Let us review what has been said so far. Given a \Fortran\ code that has
  489. been prepared in the \WEB\ format in file \.{test.web}, to get compilable
  490. code you say (using upper case solely for emphasis to distinguish the
  491. system command from the file name)
  492. {\codemode
  493. \FTANGLE\ test
  494. \noindent This produces the file \.{test.for}, which can be compiled,
  495. linked, and executed. To get the documentation of your code, you say
  496. {\codemode
  497. \FWEAVE\ test
  498. \noindent This produces the file \.{test.tex}, which can be processed with
  499. either Plain \TeX\ or \LaTeX.
  500. A worry that arises when one is deciding whether to use the \WEB\ system is
  501. whether the ^{overhead} ^^{\>{WEB}!using!overhead of}
  502. of using it will be annoying. Experience shows that
  503. the answer is generally ``No''. The \TANGLE\ processor is quite fast;
  504. the pass through \TANGLE\ typically takes a small fraction of the time to
  505. compile and link, especially for large codes. \WEAVE\ is slower (it does a
  506. \It{lot} of work!), and furthermore one must run the output of \WEAVE\
  507. through \TeX. However, when one is developing a code he typically tangles
  508. it many times for each time he weaves it, and furthermore the clarity and
  509. completeness of the resulting documentation are very much worth any
  510. additional overhead. The shift from heavily time-shared mainframes to very
  511. fast, individual workstations will further reduce any annoyance with overhead.
  512. \Knuth ^^[\>{WEB}!enhancements]
  513. \parinsert{3}{8}{0.6}
  514. ``{\ssbf FWEB} enhances the source languages by providing a relatively
  515. sophisticated, C-like macro capability together with the ability to
  516. permute pieces of the program text...''
  517. Besides providing a documentation tool, \FWEB\ enhances the source
  518. languages by providing a \[relatively sophisticated, \C-like\] macro
  519. capability ^^{macro!processing}
  520. together with the ability to permute pieces of the program text,
  521. so that a large system can be understood entirely in terms of small ^{modules}
  522. and their local interrelationships. \[Furthermore, it can even understand
  523. syntactical constructions absent from the source language and translate
  524. those into valid, compilable code; for example, it can translate the
  525. \Ratfor\ dialect of \Fortran\ directly into standard \Fortran.\]
  526. ^^{statement!translation} 
  527. The \.{TANGLE} program is so named ^^{\>{TANGLE}!name justified}
  528. because it takes a given ^{web} and moves the
  529. modules from their web structure into the order required by \[the
  530. compilers\]; the advantage of programming in \.{WEB} ^^{\>{WEB}!advantages of}
  531. is that the algorithms
  532. can be expressed in ``untangled'' form, with each module explained
  533. separately.  The \.{WEAVE} program is so named ^^{\>{WEAVE}!name justified}
  534. because it takes a given web
  535. and intertwines the \TeX\ and \[code\] portions contained in each module,
  536. then it knits the whole fabric into a structured document.  (Get it? Wow.)
  537. Perhaps there is some deep connection here with the fact that the German
  538. word for ``weave'' is ``{\it web\/}'', and the corresponding Latin
  539. imperative is ``{\it texe\/}''!
  540. \endKnuth
  541. \subsection History and design influences (Knuth).
  542. \KNUTH
  543. {\ninerm ^^(\>{WEB}!history of( ^^(references!literature(
  544. It is impossible to list all of the related work that has influenced the
  545. design of \.{WEB}, but the key contributions should be mentioned
  546. here.\quad (1)~Myrtle Kellington, as executive editor for ACM
  547. publications, developed excellent typographic standards for the
  548. typesetting of Algol programs during the 1960s, based on the original
  549. designs of Peter Naur; the subtlety and quality of this influential work
  550. can be appreciated only by people who have seen what happens when other
  551. printers try to typeset Algol without the advice of ACM's copy
  552. editors.\quad(2)~Bill McKeeman introduced a program intended to automate
  553. some of this task [Algorithm 268, ``Algol~60 reference language editor,''
  554. {\sl CACM \bf8} (1965), 667--668]; and a considerable flowering of such
  555. programs has occurred in recent years [see especially Derek Oppen,
  556. ``Prettyprinting,'' {\sl ACM TOPLAS \bf2} (1980), 465--483; G.~A. Rose and
  557. J. Welsh, ``Formatted programming languages,'' {\sl SOFTWARE Practice
  558. \char`\&\ Exper.\ \bf11} (1981), 651--669].\quad(3)~The top-down style of
  559. exposition encouraged by \.{WEB} was of course chiefly influenced by Edsger
  560. Dijkstra's essays on structured programming in the late 1960s. The less
  561. well known work of Pierre-Arnoul de Marneffe [``Holon programming: A
  562. survey,'' Univ.\ de Liege, Service Informatique, Liege, Belgium, 1973; 135
  563. pp.\null] also had a significant influence on the author as \.{WEB} was
  564. being formulated.\quad(4)~Edwin Towster has proposed a similar style of
  565. documentation in which the programmer is supposed to specify the relevant
  566. data structure environment in the name of each submodule [``A convention
  567. for explicit declaration of environments and top-down refinement of
  568. data,'' {\sl IEEE Trans.\ on Software Eng.\ \bf SE--5} (1979), 374--386];
  569. this requirement seems to make the documentation a bit too verbose,
  570. although experience with \.{WEB} has shown that any unusual control
  571. structure or data structure should definitely be incorporated into the
  572. module names on psychological grounds.\quad(5)~Discussions with Luis
  573. Trabb~Pardo in the spring of 1979 were extremely helpful for setting up a
  574. prototype version of \.{WEB} that was called \.{DOC}.\quad (6)~Ignacio
  575. Zabala's extensive experience with \.{DOC}, in which he created a full
  576. implementation of \TeX\ in \PASCAL\ that was successfully transported to
  577. many different computers, was of immense value while \.{WEB} was taking
  578. its present form.\quad(7)~David~R. Fuchs made several crucial suggestions
  579. about how to make \.{WEB} more portable; he and Arthur~L. Samuel
  580. coordinated the initial installations of \.{WEB} on dozens of computer
  581. systems, making changes to the code so that it would be acceptable to
  582. a wide variety of \PASCAL\ compilers.\quad(8)~The name \.{WEB} itself
  583. was chosen in honor of [Knuth's] wife's mother, Wilda Ernestine Bates.
  584. ^^{mother-in-law} ^^{Bates, Wilda E.}
  585. \endKnuth ^^)\>{WEB}!history of) ^^)references!literature)
  586. \Knuth
  587. The appendices to this report contain \[various examples of \WEB\
  588. programming\].  Complete \.{WEB} programs for the
  589. \.{FWEAVE} and \.{FTANGLE} processors \[are available in the source files
  590. provided with the release of \FWEB\]. A study of these examples, together
  591. with an attempt to write \.{WEB} programs by yourself, is the best way
  592. to understand why \.{WEB} has come to be like it is.
  593. \endKnuth
  594. ^^)\>{WEB}!philosophy)
  595. \section SIMPLE EXAMPLES. 
  596. Before we plunge into the depths of the \WEB\ system, it may be useful to
  597. introduce several simple examples, even though few of the concepts have
  598. been yet introduced. 
  599. \subsection A simple C program organized with {\tt FWEB}. ^^(example!C program(
  600. The first example gives the outline of a simple C~program
  601. that has 
  602. been organized with \FWEB. (If you are not familiar with~C, you should not
  603. worry. Examples from both \Fortran\ and \Ratfor\ will be given shortly, and
  604. almost all of the important \WEB\ features are language-independent.)
  605. First, we present a verbatim listing of the source code.  Then, we show how
  606. \FWEAVE\ typesets the documentation.  
  607. \HRULE
  608. \verbatim{demo0.web}
  609. \HRULE
  610. It is hoped that this example is mostly self-explanatory. Its
  611. various facets will be explained in great detail below. Here, we just
  612. observe that the source file is broken up into \It{modules} or
  613. \It{sections}, ^^<section> ^^<module>
  614. which in turn 
  615. are divided into parts, with the aid of simple commands or \It{^:control
  616. codes:} beginning with~\atcmd{}. In each section there is space for \TeX'd
  617. documentation, 
  618. ^^<documentation!\TEX>
  619. macro definitions ^^<macro!definition>
  620. (and other stuff to be explained later),
  621. and the code itself. The code can be broken up into named
  622. fragments, and these can be defined elsewhere. Therefore, each section can
  623. be short and its purpose and logical structure can be easily captured by
  624. the eye.  The other nuances of this example will be explained later.
  625. \FWEAVE\ typesets this example as follows.  (For brevity, the last few
  626. pages of the output from \FWEAVE\ are omitted here; those include the index
  627. and the table of contents.  Those items are some of the most important
  628. features of the \WEB\ system.  To see how they appear for this example, you
  629. can run \FWEAVE\ yourself on the source code for this demo, which is called
  630. \.{demo0.web}.) 
  631. \HRULE
  632. \typeset{demo0}
  633. \HRULE
  634. Note how module numbers are used both in module names and as subscripts to
  635. identifiers to help one find his way around the documentation.  (When an
  636. identifier is used in the same section in which it is defined, it is
  637. subscripted with a bullet.)  These features will be discussed at length
  638. later.
  639. ^^)example!C program)
  640. \subsection Converting a \Fortran\ program to {\tt WEB}.
  641. ^^(example!\Fortran\ program(
  642. We continue to ``learn by doing'' by considering how to convert a very
  643. simple \Fortran\ code to \WEB.  Consider the following elementary example:
  644. \filbreak
  645. \HRULE
  646. \verbatim{f0to_web.src}
  647. \HRULE
  648. The code consists of one main program and several related subroutines.  To
  649. convert such a code to \WEB, the standard procedure is to 
  650. make each program unit a separate \WEB\ section.  This is done by prefacing
  651. each program unit by (1)~an \atcmd{*} or \atcmd{\ }~command, signifying
  652. major or minor sections, respectively; (2)~explanatory
  653. \TeX\ text about the purpose and general logic of the program unit, and
  654. (3)~an \atcmd{a}~command to signal the start of the actual code.  Since the
  655. explanatory text can be absent, the quickest way of converting a \Fortran\
  656. code is to preface each subroutine with~\atcmd{\ @a}.  (Actually, one could
  657. just preface the entire code with~\atcmd{\ @a}, thereby making the entire
  658. code into just one huge section.  It would still weave and
  659. tangle correctly.  However, in this case one loses one of the most
  660. important feature of \WEB---namely, a useful index.  With everything in one
  661. big section, every index entry would refer to section~1!)  Thus, the \WEB\
  662. code one constructs from the present \Fortran\ source will look something
  663. like this:
  664. \HRULE
  665. \verbatim{f0to_web.web}
  666. \HRULE
  667. Notice that in the conversion we removed the comments that preceded the
  668. beginning of the program units.  Such comments are best incorporated into
  669. the names of major sections or expanded into a more leisurely prose that
  670. becomes the \TeX\ text.  However, we left a comment internal to the main
  671. program (almost) intact.  However, we took the opportunity to change the
  672. word ``\.{alpha}'' into the more meaningful \TeX\ form ``\.{\$\\alpha\$}''.
  673. This is not necessary when one is making a first cut at converting a
  674. working code, but in the long run it greatly improves the readability.
  675. Thus, the present example weaves to
  676. \HRULE
  677. \typeset{f0to_web}
  678. \HRULE
  679. \filbreak
  680. This leads us to a very important point:  \WEAVE\ does not just
  681. transcribe the contents of comments literally, it treats them as \TeX\ to
  682. be typeset.  Thus, if your comments weren't written with \TeX\ in mind but
  683. contain characters that are special to
  684. \TeX, such as~'\.{\$}' or~'\.{\_}', \TeX\ may complain or typeset the
  685. comments in weird ways.  Users converting large codes may find this quite
  686. annoying.  However, note the annoyance should not arise when writing a code
  687. in \WEB\ from 
  688. the start since one should be thinking about and writing in \TeX\ from the
  689. very beginning.
  690. A related point is that authors of pre-\WEB\ codes have sometimes gone to
  691. considerable lengths to align fields within comments in readable,
  692. meaningful ways.  For example, one might see something like this in a
  693. \Fortran\ code:
  694. \begintt
  695. C The method is as follows:
  696. C    (1) Specify the initial condition.
  697. C    (2) Integrate forward one step.
  698. \endtt
  699. \noindent Unfortunately, by default \WEAVE\ will undo most of this
  700. painstaking work.  Unless one does something special, the previous comments
  701. will come out looking something like this:
  702. \WC{ The method is as follows:  (1) Specify the initial
  703. condition.  (2) Integrate forward one step.}  
  704. \noindent The pretty alignment has been
  705. totally lost!  This is the price one pays for having the full power of
  706. \TeX\ available.  In \TeX, one has the powerful \.{\\halign} macro and
  707. other mechanisms to
  708. create alignments.  Had one been writing in \WEB\ from the beginning, he
  709. would have used that naturally.  The best advice, then, is:  Write all your
  710. codes in \WEB\ from the very beginning.  It's easier to do that than to
  711. convert them later---and the results are generally spectacular.
  712. Actually, there is a mechanism that will transcribe arbitrary material verbatim
  713. to the output.  This is the \It{meta-comment}:  ^^:comment!meta-:
  714. Any material enclosed
  715. between the commands~\atcmd{(} and~\atcmd{)} ^^{\>{@(}} ^^{\>{@)}}
  716. (each of which should begin in
  717. column~1 and be on a line by itself) will be appropriately enclosed
  718. in a verbatim environment (slightly different depending on whether \TeX\ or
  719. \LaTeX\ is used).  Thus, spaces and alignment are preserved in the
  720. following example:
  721. \vbox{
  722. {\codemode
  723. 0\ 2\ 4
  724. \ 1\ 3\ 5
  725. The meta-comment can be used for purposes other than comments;  see the
  726. more detailed discussion of the \atcmd{(}~command below.  In general,
  727. it is not recommended that one use meta-comments in lieu of
  728. standard \WEB\ comments whose contents are valid \TeX.  
  729. ^^)example!\Fortran\ program)
  730. In Appendices~\hbox{A--E} we describe more complicated instances of \WEB\
  731. programming.  Many further examples can be found throughout the text.  As
  732. we proceed, we will learn more methods and guidelines for writing or
  733. converting to high-quality \WEB\ code.  A more complete review of the
  734. typical conversion procedure will be given later in the section ``Usage
  735. Tips and Suggestions'' below
  736. \section GENERAL RULES.[4.14] ^^(rules!syntax(
  737. In this section we describe the syntax rules ^^[syntax rules!\WEB]
  738.  that must be followed in
  739. preparing a \WEB\ source file. Although the syntax is ultimately
  740. straightforward, the issue itself is somewhat complex because of the need
  741. to simultaneously process source codes written in several different
  742. languages. We shall therefore proceed in stages, first introducing the logic, 
  743. later discussing nuances and differences between languages.
  744. \subsection Text.
  745. The original documentation for \WEB\ stated the following:
  746. ^^[\>{WEB}!source file!syntax of]
  747. \KNUTH
  748. ``A \.{WEB} file is a long string of text that has been divided into
  749. individual lines. The exact line boundaries are not terribly crucial, and a
  750. programmer can pretty much chop up the \.{WEB} file in whatever way seems
  751. to look best as the file is being edited; but string constants and control
  752. texts must end on the same line on which they begin, since this convention
  753. helps to keep errors from propagating.  The end of a line means the same
  754. thing as a blank space.''
  755. \endKnuth
  756. \noindent Unfortunately, the situation becomes intrinsically more
  757. complicated when one desires to support a column-oriented language such as
  758. \Fortran--77.
  759. ^^{language!column-oriented} ^^{language!Fortran:\FORTRAN}
  760. However, this detail can be dealt with later. For~C and \Ratfor\
  761. free-form syntax is indeed appropriate, and once you've used it you'll
  762. probably hate going back to \Fortran's clumsy conventions.  Note that
  763. \Fortran--90 allows a free-form mode, which should be used for new codes.
  764. (However, as we will explain below, \Ratfor--90 is still easier to use than
  765. free-form \Fortran--90.)
  766. \Knuth
  767. \parinsert{3}{8}{0.6}
  768. ``Writing \WEB\ programs is something like writing \TeX\ documents, but with
  769. an additional `code mode' that is added to \TeX's horizontal mode,
  770. vertical mode, and math mode.''
  771. Two kinds of material go into \.{WEB} files: \TeX\ text and \[code\] text.
  772. ^^{text!TeX:\TEX} ^^{text!code}
  773. A programmer writing in \.{WEB} should be thinking both of the
  774. documentation and of the \bdots\ program that he or she is creating;
  775. i.e., the programmer should be instinctively aware of the different
  776. actions that \.{WEAVE} and \.{TANGLE} will perform on the \.{WEB} file.
  777. \TeX\ text is essentially copied without change by \.{WEAVE}, and it is
  778. entirely deleted by \.{TANGLE}, since the \TeX\ text is ``pure
  779. ^{documentation}.'' \[Code\] text, on the other hand, is formatted by
  780. \.{WEAVE} and it is shuffled around by \.{TANGLE}, according to rules that
  781. will become clear later. For now the important point to keep in mind is
  782. that there are two kinds of text. Writing \.{WEB} programs is something
  783. like writing \TeX\ documents, but with an additional ``\[code\] mode''
  784. ^^:mode!code: ^^:code!mode:
  785. that is added to \TeX's horizontal mode, vertical mode, and math mode.
  786. \subsection Modules.
  787. A \.{WEB} file is built up from units called {\sl modules\/} or {\sl
  788. sections\/} that are more
  789. or less self-contained.  Each \[section\] has three parts:
  790. {\narrower
  791. \yskip\item{1)} ^^:module!part!TeX\actual\TEX: ^^:part!TeX\actual\TEX:
  792.     ^^:TeX\actual\TEX!section: 
  793. A \hl{\TeX\ part}, containing explanatory material about what
  794. is going on in the module.
  795. \item{2)} ^^:module!part!definition: ^^:definition!part: ^^:part!definition:
  796. A \hl{definition part}, containing (1)~macro definitions that
  797. serve as abbreviations for \[code\] constructions that would be less
  798. comprehensible if written out in full each time, \[(2)~preprocessor
  799. commands that allow one to selectively process the macro definitions,
  800. (3)~format statements that tell \WEAVE\ how to deal with identifiers such
  801. as macro names that are not in its vocabulary, and (4)~miscellaneous
  802. commands related to operator overloading, limbo text, etc.; these will be
  803. explained later.\]
  804. \item{3)} ^^:module!part!code: ^^:part!code:
  805. A \hl{\[code\] part}, containing a piece of the program that
  806. \.{TANGLE} will produce. \It{This \bdots\ code should ideally be about a
  807. dozen lines long, so that it is easily comprehensible as a unit and so that
  808. its structure is readily perceived.} \[(Italics added.)\] \[Preprocessor
  809. commands may also appear in the code part, allowing one to selectively include
  810. or delete fragments of code.\]
  811. \yskip\noindent ^^[parts, order of]
  812. The three parts of each module must appear in this order;
  813. i.e., the \TeX\ commentary ^^{commentary!TeX:\TeX}
  814. must come first, then the definitions, and
  815. finally the \[source\] code. Any of the parts may be empty.
  816. \subsection Beginning a module. ^^{modules!beginning}
  817. \parinserto{3}{4}{0.4}
  818. A module begins with either `{\ssbf @}{\tt\ }' or `{\ssbf @*}'.
  819. A ^:module: begins with the pair of symbols~\atcmd{\ } or~\atcmd{*}, 
  820. ^^{\>{@\ }} ^^{\>{@*}}
  821. where
  822. `\.{\ }'~denotes a blank space. A module ends  ^^[module!end of]
  823. at the beginning of the next
  824. module (i.e., at the next~\atcmd{\ } or~\atcmd{*}), or at the end of the
  825. file, whichever comes first.  The \.{WEB} file may also contain material
  826. that is not part of any module at all, namely the text (if any) that occurs
  827. before the first module.  Such text is said to be ``in limbo''; 
  828. ^^:limbo!in: ^^:limbo!section: 
  829. it is ignored by
  830. \.{TANGLE} \[except for any embedded language-switching commands\] and copied
  831. essentially verbatim by \.{WEAVE}, so its function is \[primarily\]
  832. to provide any additional formatting instructions that may be desired in
  833. the \TeX\ output. Indeed, it is customary to begin a \.{WEB} file with
  834. \TeX\ code in limbo that loads special fonts, defines special macros,
  835. changes the page sizes, and/or produces a title page. \[You should also
  836. place a global language command ^^{language!global}
  837. such as~\atcmd{n} somewhere in limbo; see below.\]
  838. \endKnuth
  839. If a source file begins with~\atcmd{z} as the \It{very first} two characters, 
  840. ^^{\>{@z}} ^^{\>{@x}}
  841. all text between the~\atcmd{z} and
  842. the end of a subsequent line begun with~\atcmd{x} is completely ignored by
  843. both processors.  This material is intended to include commentary 
  844. ^^:commentary!invisible:
  845. such as author, date, version, etc.  See the demo programs scattered
  846. throughout this manual for simple examples of such commentary.
  847. \Knuth
  848. ^^[module!number of] ^^[module!references]
  849. Modules are numbered consecutively, starting with~1; these numbers appear
  850. at the beginning of each module of the \TeX\ documentation, and they appear
  851. as bracketed comments at the beginning of the code generated by that module
  852. in the \[source\] program.
  853. Fortunately, you never mention these numbers yourself when you are writing
  854. in \.{WEB}. You just say~\atcmd{\ } or~\atcmd{*} at the beginning of each new
  855. module, and the numbers are supplied automatically by \.{WEAVE} and
  856. \.{TANGLE}. As far as you are concerned, a module has a
  857. name instead of a number;
  858. ^^:module!name: ^^{\>{@<}} ^^{\>{@>}} ^^{\>{@<...@>}}
  859. such a name is specified by writing \atcmd{<}
  860. followed by \TeX\ text followed by \atcmd{>}---for example, `\.{@<Read
  861. \$\\alpha\$ and\~\$\\beta\$@>}'.  When \.{WEAVE} outputs a module name, it
  862. replaces the~\atcmd{<} and~\atcmd{>} by angle brackets and inserts the module
  863. number in small type---for example, `\WX5:Read $\alpha$ and~$\beta$\X \X'.
  864. Thus, when you read the output of \.{WEAVE} it is 
  865. easy to locate any module that is referred to in another module.
  866. For expository purposes, a module name should be a good description of the
  867. contents of that module, i.e., it should stand for the abstraction
  868. represented by the module; then the module can be ``plugged into'' one or
  869. more other modules so that the unimportant details of its inner workings
  870. are suppressed.  A module name therefore ought to be long enough to convey
  871. the necessary meaning. Unfortunately, however, it is laborious to type
  872. such long names over and over again, and it is also difficult to specify a
  873. long name twice in exactly the same way so that \.{WEAVE} and \.{TANGLE}
  874. will be able to match the names to the modules. Therefore a module name
  875. can be abbreviated ^^{module!name!abbreviating} ^^{module
  876. names!abbreviations for} ^^{\>{...} "(ellipsis")} 
  877. ^^{ellipsis "(\noexpand\dots")} 
  878. after its first appearance in the \.{WEB} file, by
  879. typing \atcmd{<$\alpha$...@>}, where $\alpha$ is any string that is a prefix of
  880. exactly one module name that appears in the file. For example, \atcmd{<Clear
  881. the arrays@>} can be abbreviated to \atcmd{<Clear...@>} if no other module
  882. name begins with the five letters `\.{Clear}'. Module names must otherwise
  883. match character for character, except that consecutive blank spaces and/or
  884. tab marks are treated as equivalent to single spaces, and such spaces are
  885. deleted at the beginning and end of the name. Thus, \atcmd{< Clear { }the
  886. arrays @>} will also match the name in the previous example.
  887. We have said that a module begins with~\atcmd{\ } or~\atcmd{*}, but we didn't
  888. say how it gets divided up into a \TeX\ part, a definition part, and a
  889. \[code\] part.
  890. \endKnuth
  891. \subsection The definition part. ^^[module!part!definition] ^^[part!definition]
  892. The \TeX\ part ends and
  893. the definition part begins with the first appearance in the module
  894. of one of a set of commands.  These are distinguished by the attribute that
  895. they do not produce compilable code but rather tell one or the other
  896. processor to do or remember something.  Those commands will be explained in
  897. detail later; briefly, they are: 
  898. ^^{\>{@d}} ^^{\>{@f}} ^^{\>{@l}} ^^{\>{@m}} ^^{\>{@v}} ^^{preprocessing}
  899. \clo{%
  900. @d&Define an ``outer macro'' whose definition will be copied to the very
  901.     beginning of the tangled output file.\cr
  902. @f&Format an identifier to behave like some other identifier.\cr
  903. @l&Specify \TeX\ text for \FWEAVE\ to output at the beginning of the
  904.     limbo section.\cr
  905. @m&Define an ``inner'' or ``\WEB\ macro'' to \FTANGLE.\cr
  906. @v&Tell \FWEAVE\ how to ``overload'' an operator.\cr
  907. @W&Tell \FWEAVE\ how to ``overload'' an identifier.\cr
  908. @\#&Begin a \WEB\ preprocessing command such as~\.{@\#if}.\cr
  909. \subsection The code part. ^^[module!part!code] ^^[part!code]
  910. \Knuth ^^[\>{@<...@>=}]
  911. \parinserto{3}{5}{0.40}
  912. ``The code part begins with the first appearance of `{\ssbf @a}' or `{\ssbf
  913. @}{\tt<}'.''
  914. The definition part ends and 
  915. the code part begins with the first appearance of~\atcmd{a} or~\atcmd{<}. 
  916. ^^{\>{@a}} ^^{\>{@<}}
  917. The latter option~\atcmd{<}
  918. stands for the beginning of a module name, which is the name of the module
  919. itself. An equals sign (\.=) must follow the \atcmd{>} at the end of this
  920. module name; you are saying, in effect, that the module name stands for the
  921. \[code\] text that follows, so you say `$\langle\,$module
  922. name$\,\rangle=\null$code text'. Alternatively, if the \[code\] part begins
  923. with~\atcmd{a} instead of a module name, the current module is said to be
  924. {\sl unnamed}. Note that (generally) module names cannot appear in the
  925. definition part 
  926. of a module, because the first~\atcmd{<} in a module signals the beginning
  927. of its \[code\] part. 
  928. Any number of module names might appear in the \[code\] part, however, once
  929. it has started.
  930. \endKnuth
  931. (Actually, in \FWEB\ module names \It{can} appear in the definition part in
  932. certain circumstances. First, a module name may appear immediately after a
  933. format command; see the discussion of~\atcmd{f} below.  Second, module names
  934. may appear in \FWEB\ macro definitions if they are begun by~`\.{\#<}'
  935. ^^{\>{\PM<...@>}} 
  936. instead of~\atcmd{<}; see the discussion of macros below.  Finally, module
  937. names may appear inside of the vertical bars that signify a shift into code
  938. mode.)
  939. \subsection How {\tt TANGLE} makes compilable programs out of modules.
  940. \Knuth ^^[\>{TANGLE}!general idea of]
  941. \parinserto{7}{5}{0.5}
  942. ``There should be at least one unnamed module, otherwise there will be no
  943. output.''
  944. The general idea of \.{TANGLE} is to make a \[compilable\] program \[(or
  945. programs, if one is mixing languages)\] out of these modules in the
  946. following way: First all the \[code\] parts of unnamed modules
  947. ^^{module!unnamed}
  948. are copied
  949. down, in order; this constitutes the initial approximation~$T_0$ to the
  950. text of the program. \It{(There should be at least one unnamed module,
  951. otherwise there will be no output.)} Then all module names that appear in
  952. the initial text~$T_0$ are replaced by the
  953. \[code\] parts of the corresponding modules, and this substitution process
  954. continues until no module names remain. Then all \[macros defined
  955. by~\atcmd{m}\] are replaced by their equivalents, according to certain rules 
  956. that are explained later. \[The resulting code may have pieces in any or
  957. all of the several supported languages~C, \Cpp, \Fortran, \Ratfor, and~\TeX.
  958. This code 
  959. is run through an \It{output driver} appropriate for the language in
  960. ^^{output!driver} ^^{driver!output}
  961. question; the driver writes files with the appropriate compiler
  962. extension---`\.{.c}', `\.{.cpp}' (`\.{.c++}' for \Unix), `\.{.for}'
  963. (`\.{.f}'~for \Unix), `\.{.rat}' (`\.{.r}' for 
  964. \Unix), or~`\.{.x}'---and syntax. ^^{extensions!file-name}
  965. ^^{extensions!compiler} 
  966. For example, 
  967. the \Fortran--77 output driver ensures that statements begin in column~7 and
  968. are correctly continued if they extend beyond column~72.\] All ^{comments}
  969. will have been removed from
  970. \[these programs\] except for the \[verbatim comments (either begun
  971. explicitly by~\atcmd{/*} or~\atcmd{//} or implicitly selected by the
  972. command-line option~\.{-v})
  973. and the\] meta-comments delimited by~\atcmd{(} and~\atcmd{)}, as explained
  974. below, and except for the module-number comments that point to the source
  975. location where each piece of the program text originated in the \.{WEB}
  976. file.
  977. \parinsert{4}{8}{0.6}
  978. ``If the same name has been given to more than one module, the code text
  979. for that name is obtained by putting together all of the code parts in
  980. the corresponding modules.''
  981. If the same name has been given to more than one module, the \[code\] text
  982. for that name is obtained by putting together all of the \[code\] parts in
  983. the corresponding modules. This feature is useful, for example, in a module
  984. named `\.{Global variables}', since a C~programmer can then declare global
  985. variables in whatever modules those variables are introduced, \[but be sure
  986. that they will all be grouped together at the beginning of the code.  A
  987. similar application arises in \Fortran\ when one is describing and defining
  988. \&{common} declarations.\] When several modules have the same name,
  989. \.{WEAVE} assigns the first module number as the number corresponding to
  990. that name, and it inserts a note at the bottom of that module telling the
  991. reader to `See also sections so-and-so'; this footnote gives the numbers of
  992. all the other modules having the same name as the present one. The \[code\]
  993. text corresponding to a module is usually formatted by \.{WEAVE} so that
  994. the output has an equivalence sign in place of the equals sign in the
  995. \.{WEB} file; i.e., the output says `$\langle\,$module
  996. name$\,\rangle\equiv\null$code text'. However, in the case of the second
  997. and subsequent appearances of a module with the same name, this `^{$\equiv$}'
  998. sign is replaced by `^{$\mathrel+\equiv$}', as an indication that the \[code\]
  999. text that follows is being appended to the
  1000. \[code\] text of another module.
  1001. \endKnuth
  1002. ^^:section:
  1003. The previous paragraph is in Knuth's original words. Note that he uses
  1004. ``module'' and ``section'' interchangably. A more precise distinction might
  1005. have been to use ``section'' for the distinct numbered entities that begin
  1006. with~\atcmd{\ } or~\atcmd{*}, and ``module'' for the concatenations of all
  1007. sections with the same names. Then one could say things like ``The unnamed
  1008. module consists of sections~1, 2, and~5.''  In any event, the user will
  1009. soon get used to how things work. In this article, we have generally chosen
  1010. to retain 
  1011. Knuth's original usage because it makes it easier to quote just what Knuth
  1012. said. 
  1013. \Levy: As \TANGLE\ starts and leaves modules, it writes down the line
  1014. number ^^{line!numbers}
  1015. of the original \WEB\ file. When the language is~C, this is done in
  1016. the form of the \C~preprocessor \&{\#line} command.
  1017. ^^{\>{\PM line}}
  1018. This means that when
  1019. the compiler gives you error messages, or when you debug your program, the
  1020. messages refer to line numbers in the \WEB\ file, rather to ones in the
  1021. \C~file. In most cases, you can even forget about the \C~file altogether.
  1022. \[For other languages, the `\&{\#}' character is changed to a comment
  1023. character. Unfortunately, in \Fortran\ and \Ratfor\ there is no compiler
  1024. feature analogous to \&{\#line} that resets the line number, so for those
  1025. languages compiler error messages will refer to the output file, not the
  1026. \WEB\ file.\] 
  1027. \subsection How {\tt WEAVE} makes a \TeX\ file containing documention.
  1028. \Knuth ^^[\>{WEAVE}!general idea of]
  1029. The general idea of \.{WEAVE} is to make a \.{TEX} file from the \.{WEB}
  1030. file in the following way: The first line of the \.{TEX} file will
  1031. \[generally be output as\] `\.{\\input fwebmac.sty}'; 
  1032. ^^:\>{fwebmac}!\>{.sty}:
  1033. this will cause \TeX\ to read in the macros that define \.{FWEB}'s
  1034. documentation 
  1035. conventions. \[(If you don't want this line to be first for some tricky
  1036. reason, turn it off with the command-line option
  1037. `\.{-w}'. ^^{\>{-w}}
  1038. However, you 
  1039. must then say yourself `\.{\\input fwebmac.sty}' somewhere in limbo.)\]  
  1040. \[Next may be inserted special \TeX\ material generated automatically by
  1041. the~\atcmd{l} or \atcmd{v}~commands; see below.\]
  1042. next lines of the file will be copied from whatever \TeX\ text is in limbo
  1043. ^^{limbo!section}
  1044. before the first module.  Then comes the output for each module in turn,
  1045. possibly interspersed with end-of-page marks.  Finally, \.{WEAVE} will
  1046. generate a cross-reference ^{index} that lists each module number in which
  1047. each \[code\] identifier appears, and it will also generate an alphabetized
  1048. list of the module names, as well as a ^{table of contents} that shows the
  1049. page and module numbers for each ``starred'' module.
  1050. \subsection Starred (major) modules. ^^:module!starred:
  1051. What is a ``starred'' module, you ask?
  1052. A module that begins with~\atcmd{*} ^^[\>{@*}]
  1053. instead of~\atcmd{\ } is slightly special in that it denotes a new major
  1054. group of modules. The~\atcmd{*} should be followed by the title of this
  1055. group, followed by a period. Such modules will always start on a new page
  1056. in the \TeX\ output, and the group title will appear as a running headline
  1057. on all subsequent pages until the next starred module. The title will also
  1058. appear in the table of contents, and in boldface type at the beginning of
  1059. its module. Caution: Do not use \TeX\ control sequences in such titles,
  1060. unless you know that the \.{fwebmac} macros will do the right thing with
  1061. them. The reason is that these titles are converted to uppercase when they
  1062. appear as running heads, and they are converted to boldface when they
  1063. appear at the beginning of their modules, and they are also written out to
  1064. a table-of-contents file used for temporary storage while \TeX\ is working;
  1065. whatever control sequences you use must be meaningful in all three of these
  1066. modes.
  1067. \endKnuth
  1068. Starred sections
  1069. have associated level numbers, ^^:level!numbers: ^^:level!of starred section:
  1070. ^^:subsection!level number of:
  1071. where 0~denotes the most significant level,
  1072. 1~denotes a ^:subsection:, 2~denotes a subsubsection, and so on.  You can
  1073. indicate the level number in several ways.  First, if the command~\atcmd{*}
  1074. is not immediately followed by a digit, then the level is~0.
  1075. (This was the only possibility in the original \WEB\ design.)
  1076. Next, if \atcmd{*}~is followed by a positive digit, then that digit
  1077. indicates the level.  (Be default, that digit must be $\le 4$.)  Thus, you
  1078. can say 
  1079. {\codemode
  1080. @* MAJOR.  (The level is 0.)
  1081. @*3 Subsubsubsection.  (The level is 3.)
  1082. \noindent Note that entries are made in the table of contents for all starred
  1083. sections, including those whose level is greater than~0.
  1084. Level numbers are processed by \.{fwebmac} macros, not by code hard-wired
  1085. into \FWEAVE.  The level number is supplied as an argument to various
  1086. \.{fwebmac} macros, and one can redefine those macros to achieve various
  1087. special effects.  For example, entries in the table of contents are
  1088. formatted by the macro~\.{\\WZ} ^^{\CS{WZ}}
  1089. (which is defined inside the table-of-contents macro~\.{\\Wcon}), ^^{\CS{Wcon}}
  1090. whose first argument is the level number~$n$.  By default, the entry is just
  1091. indented by $n$~ems.  However, it is straightforward to achieve more
  1092. sophisticated effects (such as various fonts or case) by enhancing the
  1093. definition of~\.{\\WZ}  to include
  1094. an \.{\\ifcase} construction.  (See how this is done in \.{fwebman.tex} for
  1095. the table of contents for this manual.)
  1096. Similarly, by default major sections get a page break in the woven output,
  1097. whereas subsections do not; however, that can also be changed by redefining
  1098. the \.{fwebmac} macro \.{\\Wsectionbreak}. ^^{\CS{Wsectionbreak}}
  1099. \Knuth
  1100. The \TeX\ output produced by \.{WEAVE} for each module consists of the
  1101. following: First comes the module number (e.g., `\.{\\WM123.}' ^^{\CS{WM}}
  1102. at the
  1103. beginning of module 123, except that `\.{\\WN}' ^^{\CS{WN}}
  1104. appears in place of `\.{\\WM}' at the beginning of a starred module). Then
  1105. comes the \TeX\ part of the module, copied almost verbatim except as noted
  1106. below. Then comes the definition part and the \[code\] part, formatted
  1107. so that there will be a little extra space between them if both are
  1108. nonempty. The definition and \[code\] parts are obtained by inserting
  1109. a bunch of funny-looking \TeX\ macros into the \[source\] program; these
  1110. macros handle typographic details about fonts and proper math spacing,
  1111. as well as line breaks and indentation.
  1112. \endKnuth
  1113. (The original \WEB\ employed control sequences such as `\.{\\M}' instead of
  1114. `\.{\\WM}'. This makes the \.{tex}~file somewhat shorter and more readable
  1115. and makes the input 
  1116. phase of \TeX\ run a tiny bit faster. However, it seems undesirable to deny
  1117. the user most of the single-character upper-case control sequences; the
  1118. present \FWEB\ opts for user convenience.)
  1119. \Knuth ^^[\>{"|..."|}]
  1120. \subsection Code mode.
  1121. When you are typing \TeX\ text, you will probably want to make frequent
  1122. reference to variables and other quantities in your \bdots\ code, and you
  1123. will want those variables to have the same typographic treatment when they
  1124. appear in your text as when they appear in your program.  Therefore the
  1125. \.{WEB} language allows you to get the effect of \[source code\] editing
  1126. within \TeX\ text, if you place `\.|' marks before and after the \[code\]
  1127. material. For example, suppose you want to say something like this \[while
  1128. documenting \Fortran\ code\]:
  1129. \endKnuth
  1130.         \hbox{The \&{integer} variable \\{itype} is used in such
  1131. statements as 
  1132.                 $\&{if}(\\{itype}\WI\|m)\dots$} 
  1133. The \TeX\ text would look like this in your \.{WEB} file:
  1134. $$\hbox{\.{The |integer| variable |itype| is used in such
  1135. statements as 
  1136.         |if(itype\ !=\ m)|\dots}}
  1137. \noindent
  1138. Note that the \WEB\ file contained the construction `\.{!=}' instead of
  1139. \Fortran--77's standard (and archaic)~`\.{.ne.}'. In fact, you could have typed
  1140. either, but \WEB\ gives you the flexibility to type the more modern symbols
  1141. if you wish, thereby helping you to write clearer code. The options will be
  1142. explained in detail later; as much as possible, they follow the
  1143. conventions for~C.  Also, observe that either construction is
  1144. woven into the more meaningful symbol~`$\WI$'.
  1145. \Knuth
  1146. \bdots
  1147. Incidentally, the cross-reference index that \.{WEAVE} would make, in the
  1148. presence of documentation like this, would include the current module number as
  1149. one of the index entries for \\{itype}, even though \\{itype} might not
  1150. appear in the \[code\] part of this module. Thus, the index covers
  1151. references to identifiers in the explanatory comments as well as in the
  1152. program itself; you will soon learn to appreciate this feature. However,
  1153. the identifiers \&{integer},
  1154. \&{if}, and \|m would not be indexed,
  1155. because \.{WEAVE} does not make index entries for ^{reserved words} or
  1156. single-letter identifiers.
  1157. ^^{identifiers!single-letter}
  1158. Such identifiers are felt to be so ubiquitous
  1159. that it would be pointless to mention every place where they occur.
  1160. \comment
  1161. Speaking of identifiers, the author of \.{WEB} thinks that
  1162. \\{IdentifiersSeveralWordsLong} look terribly ugly when they mix
  1163. uppercase and lowercase letters. He recommends that
  1164. \\{identifiers\_several\_words\_long} be written with underline characters
  1165. to get a much better effect. The actual identifiers sent to the \PASCAL\
  1166. compiler by \.{TANGLE} will have such underlines removed, and \.{TANGLE}
  1167. will check to make sure that two different identifiers do not become
  1168. identical when this happens. (In fact, \.{TANGLE} even checks that
  1169. the first seven characters of identifiers are unique, when lowercase
  1170. letters have been converted to uppercase; the number seven in this
  1171. constraint is more strict than \PASCAL's eight, and it can
  1172. be changed if desired.) The \.{WEAVE} processor will properly
  1173. alphabetize identifiers that have embedded underlines
  1174. when it makes the index.
  1175. \endcomment
  1176. Although a module begins with \TeX\ text and ends with \[code\] text, we have
  1177. noted that the dividing line isn't sharp, since \[code\] text can be included
  1178. in \TeX\ text if it is enclosed in `\pb'.  Conversely, \TeX\ text also
  1179. appears frequently within \[code\] text, because everything in ^:comments:
  1180. (i.e., between \[`\.{/*}' and `\.{*/}', or between~`\.{//}' and the next
  1181. newline\]) is treated as \TeX\ text. 
  1182. Furthermore, a module name consists of \TeX\ text; thus, a \.{WEB} file
  1183. typically involves constructions like `\.{if}(\.x\ \.{==}\ \.0)\
  1184. \.{@<Empty}\ \.{the}\ \.{|buffer|}\ \.{array@>}' where we go back and forth
  1185. between \[code\] and \TeX\ conventions in a natural way.
  1186. \endKnuth
  1187. In the original \WEB\ design, a module name (\.{@<\dots@>}) was not allowed
  1188. between the vertical bars, because the first occurrence of the name
  1189. signified the beginning of the code part.  Beginning with version~1.30,
  1190. this restriction has been removed.  Thus, one can include in his \TeX\
  1191. documentation statements like ``See section \.{|@<A@>|} for \dots''.  Since
  1192. code mode is allowed inside module names, it is now also possible to have
  1193. module names within module names, as in ``\.{@<A = |@<B@>|@>}''.
  1194. (Obviously, it's possible to abuse this flexibility.)
  1195. \subsection Fortran demo program. ^^(example!Fortran program(
  1196. To summarize and illustrate some of what has just been said, here is an
  1197. (incomplete) example of a \Fortran\ program that is intended to read some
  1198. data, process it, and graph the results. This uses several features that
  1199. have not yet been explained, namely macro definition, preprocessor
  1200. commands, and format commands, but these are either fairly obvious and/or
  1201. can be ignored for now.  This example tries to demonstrate how one should
  1202. liberally use named modules
  1203. ^^{module!named}
  1204. to enhance the logical structure of each module
  1205. and to keep the length of each module quite short, and how to use vertical
  1206. ^^<bars, vertical> ^^<\>{"|..."|}>
  1207. to intersperse code mode with TeX'd documentation.
  1208. \HRULE
  1209. \verbatim{demo1.web}
  1210. \HRULE
  1211. \FWEAVE\ typesets this example as follows.
  1212. \HRULE
  1213. \typeset{demo1}
  1214. \HRULE
  1215. ^^)rules!syntax)
  1216. ^^)example!Fortran program)
  1217. \vfill\Eject
  1218. \subsection Modules versus functions.[4.11.3] 
  1219. ^^[modules!use of] ^^[functions!use of]
  1220. Clearly the concept of \WEB\ modules leads to great flexibility  and
  1221. readability in the construction of source codes.  However, modules can also
  1222. be misused or, in particular, \It{overused}, ^^{modules!overuse of}
  1223. and these difficulties are not uncommon for beginning programmers in \WEB.  
  1224. \subsubsection When to use named modules.
  1225. \parinserto{5}{7}{0.7}
  1226. ``Named modules should be used when the overhead of a function call is
  1227. unacceptable, such as, for example, in a computationally bound inner loop.''
  1228. The problem is that although in many ways modules are functionally quite
  1229. similar to functions or subroutines, they are not identical.  Of course,
  1230. modules do not take arguments, but that is not so much the point.  Of more
  1231. concern is that it is in principal possible to create a very large code
  1232. with just one main program (consider the above example), even though no
  1233. section is more than about a dozen lines long, just by nesting named
  1234. modules to arbitrary levels.  That this is undesirable is usually
  1235. emphasized when one attempts to debug such a code; he may find that it is
  1236. not easy to set a breakpoint at a module, whereas had each module been a
  1237. function call one could have set many breakpoints and obtained a detailed
  1238. picture of the control flow.  Also, many compilers have limitations on the
  1239. maximum length of a function.  A partial solution to this is discussed in a
  1240. later subsection on debugging, but it is nevertheless true that one should
  1241. often use function calls instead of modules.  Named modules should be used
  1242. when the overhead of a function call is unacceptable, such as, for example,
  1243. in a computationally bound inner loop.  They also find an important use in
  1244. making constructions such as large \&{switch} statements readable; each
  1245. case of the \&{switch} can be a separate module.  However, very large
  1246. blocks of code, especially in outer sections of the program, should
  1247. probably be accessed with function calls, if possible.  Note, though, that
  1248. certain blocks of code, such as \&{common} declarations in \Fortran, cannot
  1249. be replaced by function calls.  For such cases, the use of named modules is
  1250. almost always desirable.
  1251. As an example of this discussion, it would actually be better to code the main
  1252. program of the preceding example as follows:
  1253. {\codemode
  1254. program main
  1255. @<Common declarations@>
  1256. call input
  1257. call process
  1258. call graph
  1259. \noindent Since the main program is not inside a critical inner loop, the
  1260. slight extra overhead of the subroutine calls will be imperceptible, and
  1261. one can easily set a debugging breakpoint at each of the fundamental
  1262. subroutines \\{input}, \\{process}, and \\{graph}.  A named module is
  1263. properly used here to insert the common declarations, which cannot be
  1264. replaced by a subroutine call.
  1265. \dsubsubsection Self-documentation and cross-referencing for named modules and
  1266. identifiers. ^^{module!references}
  1267. One of the great virtues of employing named modules is that the names are
  1268. \It{self-documenting}.  For example, it is much more illuminating to see
  1269. ``\WX98:Check that $\theta$~lies in the range $-\pi \le \theta < \pi$; issue
  1270. a warning message otherwise\X \X'' than to have to remember what the
  1271. statement ``\&{call} \\{check}'' does.  Furthermore, in the original
  1272. \WEB\ design it was not immediately obvious where \\{check} was defined.
  1273. One had to turn first to the index, look up \\{check}, then turn back to
  1274. the desired section.  The extra step of accessing the index is unnecessary
  1275. with module names, which have the relevant section number built in.
  1276. However, beginning with \FWEB\ version~1.20, certain identifiers such as
  1277. function names and macro definitions also carry the
  1278. section name in which they were defined, displayed as a subscript---e.g.,
  1279. \\{check}\WIN1{98}.  ^^{subscripts, module number} ^^{module!references}
  1280. Although this does not solve the problem of
  1281. self-documentation, it does expedite finding one's way around the code.
  1282. This mechanism is discussed further in the section on ``Forward
  1283. referencing'' below.
  1284. In fact, it's possible to the virtues of both self-documentation and
  1285. function calls if one is willing to do a bit of extra typing.  Consider the
  1286. following:
  1287. {\codemode
  1288. @<Check that $\\theta$ lies in the range $-\\pi \\le \\theta < \\pi$;
  1289. issue a warning message otherwise@>=
  1290. \Tab call check
  1291. \noindent With this trick, the documentation shows clearly what is really
  1292. happening, but one can still set a breakpoint at \\{check} for convenient
  1293. debugging. 
  1294. \subsubsection {\tt WEB} programming and \Unix.
  1295. In summary, both function calls and named modules can be used to good
  1296. advantage in \WEB\ programming.  If they are used properly, the resulting
  1297. product can be amazingly easy to understand and maintain.
  1298. \parinsert{2}{4}{0.35}
  1299. ``{\ssbf WEB} and {\ssbf UNIX} are not in conflict.''
  1300. Nevertheless, the possibility of indiscriminate use of modules has led some
  1301. programmers, particularly those used to \Unix, to suggest that \WEB\
  1302. programming is a step backwards and defeats the utility of other tools such
  1303. as the \.{make} utility.  Those programmers will delegate each function to
  1304. a separate file, then use the \.{make} utility to keep them updated as
  1305. necessary.  However, although this keeps the amount of compiling to a
  1306. minimum, this extreme limit can also be criticized on the grounds that it
  1307. is very difficult to maintain a sensible, coherent documentation, which was
  1308. the primary goal of the \WEB\ system.  More reasonably, the ideal solution
  1309. lies somewhere between the two extremes.  Generally it is reasonable and
  1310. efficient to combine at least several functions into one source file.
  1311. Furthermore, all but the very shortest functions can benefit from being
  1312. broken into named modules, and common \WEB\ macros can be easily included
  1313. with each separate file.  \WEB\ and \Unix\ are not in conflict; they both
  1314. provide powerful tools that can be simultaneously applied to complicated
  1315. programming problems.  Both systems provide the programmer with a great
  1316. deal of power.  It is up to him to use that power wisely and with
  1317. discipline.  As Knuth admits, the users of \WEB\ must be sophisticated, but
  1318. they reap significant rewards in return.
  1319. \section The PHASES of \WEB.[5.3]  ^^(\>{WEB}!phases of(
  1320. It is not necessary to know in great detail just how \WEB\ accomplishes its
  1321. various tasks in order to use it effectively. However, to fully understand
  1322. some of the material to follow, especially topics related to macro
  1323. processing, it is necessary to appreciate that \WEB\ processes its input in
  1324. several distinct ^[phases]: two for \TANGLE; three for \WEAVE. These phases
  1325. are explained briefly here.
  1326. First, we must remark that the \WEB\ processors are best viewed as
  1327. consisting of three parts: an \It{input driver};
  1328. ^^{driver!input}
  1329. the \It{processor proper}; and
  1330. an \It{output driver}.
  1331. ^^{driver!output}
  1332. Each source language has (at least in principle) a distinct input driver.
  1333. The role of the input drivers is to preprocess the incoming text into a
  1334. uniform syntax that can be understood by the processor proper. For example,
  1335. idiosyncratic commenting styles such as \Fortran--77's column~1 convention are
  1336. converted by the input driver to the standard C~style that the innards of
  1337. the processors understand. For \WEAVE, the output driver is common to all
  1338. languages; it creates the \.{tex}~file. For \TANGLE,
  1339. the output driver is more or less the inverse of
  1340. the input driver; it creates~\.c, \.{for}, \.{rat}, or~\.{tx}~files.
  1341. In the following discussion, ``input'' is best thought of
  1342. as the input to the processor proper, or equivalently as the preprocessed
  1343. output of the input driver.
  1344. \subsection Phase 1.
  1345. For both processors, phase one involves \It{^{tokenization}} of the input.
  1346. If the input is \TeX\ material, it is skipped by \TANGLE\ or absorbed
  1347. essentially unchanged by \WEAVE. Code material is broken up into
  1348. identifiers, numerical constants, character strings, etc., and these are
  1349. represented by special codes. For ease in working with \WEB\ macros,
  1350. the concept of \It{identifier} is generalized
  1351. somewhat from the syntax of any of the supported source languages:
  1352. ^:identifiers: are character sequences of arbitrary length that contain either
  1353. an alphabetic character (\.{A-Z} or \.{a-z}), a digit (\.{0-9}), an
  1354. underscore~('\.\_'), a dollar sign~('\.\$'), or, when the language is
  1355. neither~\C, \Cpp, nor \Fortran--90, a per~cent sign~('\.\%');
  1356. they may not begin with a digit. 
  1357. Case is always significant. ^^[case, significance of]
  1358. Thus, examples of unique identifiers are
  1359. {\codemode
  1360. a, A, UPPER_and_lower_case, i5, SYS$TEST, $1, _reserved, %loc
  1361. \noindent Avoid defining macros or C~identifiers that begin with an
  1362. underscore; such 
  1363. identifiers may be used internally by the system.   Dollar signs or (generally)
  1364. per~cent signs are permitted since some compilers use them to identify
  1365. extensions to the standard languages.  It is common to enter the source
  1366. code entirely in lower case, thereby reserving upper case for possible use
  1367. in macro definitions.  In particular, the reserved words of~C or \Fortran,
  1368. such as \&{for} or \&{dimension}, are understood only in lower case.
  1369. \parinsert{2}{5}{0.5}
  1370. ``Avoid defining macros or C identifiers that begin with an underscore.''
  1371. When an identifier or module name is recognized, both \TANGLE\ and \WEAVE\
  1372. store it in a table, along with its special code. Otherwise, however, the
  1373. two processors do different things in phase one. ^^[phase!1]
  1374. \TANGLE\ ^^[phase!1!\>{TANGLE}]
  1375. stores all of the
  1376. tokenized code, filing it into the appropriate (unnamed or named) module.
  1377. It also memorizes macro definitions.
  1378. \WEAVE, on the other hand, does \It{not} store the code during phase one.
  1379. ^^[phase!1!\>{WEAVE}]
  1380. Rather, it merely processes any format (\.{@f}) definitions or operator
  1381. overload 
  1382. (\.{@v}) commands (both explained later) and constructs a 
  1383. cross-reference table for the identifiers and module names. This
  1384. preliminary pass is required in order that forward references to named
  1385. modules and certain identifiers can be resolved.
  1386. ^^{modules!forward references to}
  1387. \subsection Phase 2.
  1388. During phase two, ^^[phase!2] ^^[phase!2!\>{TANGLE}]
  1389. \TANGLE\ outputs the code it has stored. As explained
  1390. earlier, it begins with the contents of the unnamed module.
  1391. ^^{module!unnamed}
  1392. If at any point it encounters a reference to a named module, 
  1393. ^^{module!named}
  1394. it takes a detour to dump out the contents of that module. Since modules may
  1395. contain references to other modules, and such references can be nested to
  1396. arbitrary depth, the output routine is recursive.  As text is output,
  1397. each identifier is examined to see whether it has been defined as a \WEB\
  1398. macro. If so, the macro is expanded;
  1399. ^^{macro!expansion}
  1400. that expansion procedure is also
  1401. recursive. In the \Ratfor\ mode, certain identifiers such as \&{for} or
  1402. \&{switch} have special significance. These are not macros, exactly;
  1403. rather, they are special keywords signifying that special actions should be
  1404. taken on the text that follows. When one of these keywords is recognized, a
  1405. special \It{statement translation function} is invoked.
  1406. ^^{statement!translation}
  1407. The input to that
  1408. function is the raw output of \TANGLE. The function may request further output,
  1409. possibly storing up text and outputting it in a different order, possibly
  1410. inserting additional statements such as \&{goto} into the output. The
  1411. ultimate output from the statement translator will be the
  1412. \Fortran\ equivalent of the original \Ratfor\ construction. Macros and
  1413. module names will have been expanded properly during that output.
  1414. Thus, at the end of phase two of \TANGLE\ all of the code will have been
  1415. output in the appropriate order, in a form acceptable to a language
  1416. compiler.  (See the example in Appendix~D.)
  1417. Phase two of \WEAVE\ ^^[phase!2!\>{WEAVE}]
  1418. is more complicated. For each module, 
  1419. \WEAVE\ reads the 
  1420. source file again. It copies the \TeX\ material to the output essentially
  1421. unchanged. It tokenizes the code and stores it along with the
  1422. cross-reference information that it collected during phase one.  At the end
  1423. of the module, it then analyzes the code hunting for constructions it
  1424. understands, such as expressions, loops, entire functions, etc. These are
  1425. processed and output into a series of \TeX\ macros that will typeset the
  1426. code in a useful, visually appealing way.  (See the examples in Appendices~B
  1427. and~E.) 
  1428. \subsection Phase 3.
  1429. \TANGLE\ has no phase~three.
  1430. Phase three ^^[phase!3] ^^[phase!3!\>{WEAVE}]
  1431. of \WEAVE\ sorts the cross-reference information, 
  1432. ^^{cross-references}
  1433. and writes out the ^{index}, alphabetized list of module names,
  1434. ^^{module names!alphabetized list of}
  1435. and the ^{table of contents}.  In order to expedite advanced editing and
  1436. other tasks, both the index and list of module names are written to
  1437. separate files, which by default are named \.{INDEX.tex} and \.{MODULES.tex}.
  1438. ^^{\>{INDEX.tex}} ^^{\>{MODULES.tex}}
  1439. (These can be changed with the style file; see below.)
  1440. ^^)\>{WEB}!phases of)
  1441. \dsection LANGUAGES.[6.1]  ^^(languages(
  1442. This version of \FWEB\ supports a variety of source languages: 
  1443. \Fortran\ (both \Fortran--77 and \Fortran--90), ^^{language!Fortran:\FORTRAN}
  1444. \Ratfor\ ^^{language!Ratfor}
  1445. (both \Ratfor--77 and \Ratfor--90; to be explained shortly), \C, \Cpp,
  1446. ^^{language!C} ^^{language!\Cpp} 
  1447. and \TeX. ^^{language!\>{TEX}}  
  1448. (A future version may support the language 
  1449. \.{MAKE}, defined to be the syntax of \Unix\ make files.)
  1450. These languages can be intermixed within one
  1451. \WEB\ run.  In the simplest situation the programmer will use just
  1452. one language.  However, it is not uncommon to code the outer, control part
  1453. of a large program in, say, the C~language while writing the inner,
  1454. computationally bound routines in \Fortran.  In such situations, \FWEB's
  1455. language facilities are quite useful, since it enables one to maintain the
  1456. documentation for the entire code in one unified source file.
  1457. \comment
  1458. Internally, \FWEB's notion of
  1459. language sometimes differs somewhat from the traditional one.  In
  1460. particular, most 
  1461. people would likely say that~\C\ and \Cpp~are distinct languages, in the
  1462. sense that one uses different compilers to process them.  However,  for
  1463. \It{almost} all purposes \C~is a proper subset of~\Cpp.  For this reason,
  1464. in order 
  1465. to keep the size of various internal tables as small as possible and in
  1466. order to conveniently share large and complicated blocks of code, \WEB\
  1467. treats~\C\ and~\Cpp\ as two dialects of one language, namely~\.C.  A
  1468. subsidiary flag is used to distinguish between the two when necessary.
  1469. Thus, as explained below, one uses the commands~\atcmd{c} or~\atcmd{c++} to
  1470. process standard~\C\ or~\Cpp, respectively.  Both of these commands sets
  1471. \FWEB's current language to~\.C; the ``\.{++}'' sets a subsidiary flag.  The
  1472. same mechanism is used to distinguish between \Fortran--77~(\atcmd{n}) and
  1473. \Fortran--90~(\atcmd{n9}), 
  1474. which truly are dialects of the single language \.{FORTRAN}, and between
  1475. \Ratfor--77~(\atcmd{r}) and \Ratfor--90~(\atcmd{r9}).
  1476. \endcomment
  1477. \subsection Selecting a language.[6.1.3]
  1478. It is very simple to tell \WEB\ which language is in effect at any point.
  1479. \subsubsection Language abbreviations. ^^:language!abbreviations:
  1480. Each language has an abbreviation that can be used to identify it.  These
  1481. are as follows: 
  1482. $$\vbox{\halign{#\hfil&\ ---\ '{\tt#}'\hfil\cr
  1483. \C*&c\cr
  1484. \Cpp*&c++\cr
  1485. \Fortran--77*&n\cr
  1486. \Fortran--90*&n9\cr}}
  1487. \qquad
  1488. \vbox{\halign{#\hfil&\ ---\ '{\tt#}'\hfil\cr
  1489. \MAKE&k\cr
  1490. \Ratfor--77*&r\cr
  1491. \Ratfor--90*&r9\cr
  1492. \TEX&x\cr}}
  1493. (Strictly speaking, only the first character is the abbreviation; any
  1494. subsequent text is an optional argument, as discussed in more detail below.
  1495. Also, note the `\.n' for fortra\.N; an `\.f' conflicts with the format
  1496. command~\atcmd{f}.)  
  1497. Each of the starred languages can be invoked by its own command-line option
  1498. or control code (these are explained below in more detail).  For example,
  1499. \C~can be invoked from the command line by the option~`\.{-c}', and from
  1500. within the \.{web}~source by~\atcmd{c}.  Other languages, such as \.{TEX} or
  1501. (in the future)
  1502. \MAKE, must be invoked by the general language command~`\.{-L$l$}' or
  1503. \atcmd{L$l$}, ^^{\={-l}{-L{\it l}}}
  1504. where $l$~is one of the language symbols listed above.  (Case is
  1505. significant; `\.{-l}'~means something entirely different.) ^^{\>{-l}}
  1506. For example, one
  1507. can invoke the \.{\TeX} language by~\atcmd{Lx}.  This general command also
  1508. works for the starred languages, so that \atcmd{n}~is equivalent to~\atcmd{Ln}.
  1509. \subsubsection Global language.
  1510. \FWEB\ has the concept of a \It{global language}.
  1511. ^^:language!global:
  1512. The global language is defined to be the language in force when the first
  1513. module is encountered; namely, at the very end of the limbo stage.
  1514. ^^[limbo!section!changing language in]
  1515. It is used as the starting language of the unnamed module and of the \TeX\
  1516. parts of each section.  The default global language is
  1517. \Fortran--77, ^^:language!global!default: ^^{language!Fortran:\FORTRAN}
  1518. a reluctant concession to the physics world. However,
  1519. \It{it is 
  1520. not recommended that you use \Fortran--77 for new code}, as you will lose a
  1521. good deal of the statement-processing abilities of \FTANGLE. First, you
  1522. should consider switching to~\C\ or~\Cpp, which are choices superior to
  1523. \Fortran\ for many applications. However, if you choose to write in a
  1524. \Fortran\ dialect, then \It{it is 
  1525. strongly recommended that you use \Ratfor}, ^^{language!Ratfor}
  1526. as described elsewhere in
  1527. this document. Your code will be easier to write (it will be logically
  1528. clearer and will involve fewer keystrokes), the result will be
  1529. substantially more readable, and, therefore, you will ultimately be more
  1530. productive.
  1531. \parinsert{2}{5}{0.4}
  1532. ``It is not recommended that you use Fortran--77 for new code.''
  1533. One can override the default global language of \Fortran--77 in two ways. 
  1534. ^^{language!global!setting the}
  1535. First, although it
  1536. is {\it not recommended} except for special situations, one can set it from the
  1537. command line by using one of the options `\.{-c}', `\.{-r}', `\.{-n}',
  1538. or~`\.{-L$l$}'. 
  1539. ^^{\>{-c}} ^^{\>{-r}} ^^{\>{-n}} ^^{\={-l}{-L{\it l}}}
  1540. Second, you can insert one of the language switching commands
  1541. \atcmd{c}, \atcmd{r}, \atcmd{n}, or~\atcmd{L$l$}
  1542. ^^{\>{@c}} ^^{\>{@r}} ^^{\>{@n}} ^^{\={@l}{@L{\it l}}}
  1543. anywhere in the limbo section. Note that if
  1544. you have such an explicit language command in your file, it will override
  1545. anything that was said on the command line. (You will be warned.)  The best
  1546. practice is to put the global language command at the very beginning or the
  1547. very end of the limbo section.  (If you put it at the beginning, it must
  1548. at present follow any \.{@z\dots@x} ignorable commentary.)
  1549. ^^{commentary!invisible} 
  1550. If you're programming only in \Fortran--77, you don't need the 
  1551. \.{@n}~command. However, as a matter of style, and for compatibility with
  1552. future releases, it's best to always insert a language command explicitly.
  1553. \subsubsection Changing languages within modules.
  1554. ^^[language!changing!within modules] ^^[module!language of]
  1555. All modules, both named and unnamed, have a language. The \TeX\ part of
  1556. each section will begin in the global language. Now although language
  1557. doesn't matter for \TeX\ text, it does matter if you shift into code mode
  1558. ^^{code!mode} ^^{mode!code}
  1559. by using vertical bars.  Unless told otherwise, code between vertical bars
  1560. will be in whatever language is currently in force (generally, this will be
  1561. the global language). If, however, you want that code to be interpreted
  1562. according to some other language, you can put a language command
  1563. immediately after the opening vertical bar, as in `\.{|@n real a(0:n)|}' or
  1564. `\.{|@r repeat \{i=f(i);\} until(i > 10);|}'; that language switch will be
  1565. local to the barred material. 
  1566. Except for this local use of language commands, it is safest (because of
  1567. certain restrictions in the \Fortran\ mode) and logically and visibly
  1568. clearest that language commands begin in column~1, on a line by themself.
  1569. You can also place a language command anywhere in the \TeX\ part, not
  1570. just between bars, to reset the language for the rest of that part, but
  1571. this is neither recommended nor usually necessary.
  1572. \parinsert{2}{5}{0.55}
  1573. ``You can change languages in the unnamed module, but that change is local
  1574. to one section.''
  1575. When the command~\atcmd{a}, which signifies the start of the unnamed module,
  1576. is encountered (either for the first or for subsequent times), the language
  1577. reverts to the global language. You can change languages in the unnamed
  1578. module, but that change is local to one section; it is cancelled by the
  1579. next~\atcmd{*} or~\atcmd{\ }. \FTANGLE\ sorts out the languages and deflects
  1580. the code to the appropriate output files. \FWEAVE\ prints the language
  1581. commands as a marginal note, and it identifies the language of any module
  1582. name not in the global language with a superscript, as in
  1583. \atcmd{<C code@>}$^{\textstyle\tt C}$.
  1584. \parinsert{1}{5}{0.6}
  1585. ``The code parts of named modules inherit the language in force when
  1586. that name was first encountered.''
  1587. The code parts of named modules inherit the language in force \It{when
  1588. that name was first encountered}. That language attribute propagates
  1589. through all levels of nesting, so that if you have a named module in, say,
  1590. the C~language, all named modules referenced for the first time in that
  1591. module will automatically be interpreted in~C; you don't need to preface
  1592. each of those (possibly many) modules with an explicit~\atcmd{c}.
  1593. However, if, for example, the global language is \Fortran, there must be at
  1594. least one~\atcmd{c} somewhere in your file in order to mix in any C~routines
  1595. at all. The most painless way to do this is to switch languages in the
  1596. unnamed module. Put a language command just before a reference to a named
  1597. module that you want to be interpreted in~\C. That one command is all you
  1598. need to have everything connected with that named module also be understood
  1599. to be in~C.
  1600. \It{When the language is \Fortran--77, begin all \atcmd{}~commands in
  1601. column~1.} This restriction is imposed in order to help simplify the job of
  1602. the \Fortran\ input driver, which converts the column-oriented syntax of
  1603. traditional \Fortran\ to the free-form syntax that the innards of the \WEB\
  1604. processors understand.  It's not a bad programming style in any event.
  1605. \subsection Demo program with two languages. 
  1606. ^^(example!program with two languages( 
  1607. As an example, here's how you might handle a main program in \Fortran\ and
  1608. some subroutines written in~\C, all of which are here put into the unnamed
  1609. module. 
  1610. ^^<language!changing>
  1611. \HRULE
  1612. \verbatim{demo2.web}
  1613. \HRULE
  1614. \FWEAVE\ typesets this example as follows.  Note the marginal
  1615. notation~\.{@Lc}, which marks the language change~\atcmd{c}.  Also notice how
  1616. module names not in the global language are superscripted with a language
  1617. symbol.  
  1618. \HRULE
  1619. \typeset{demo2}
  1620. \HRULE
  1621. \noindent When the definition of module \.{@<C code@>} is encountered,
  1622. \FWEAVE\ will properly format it in~\C. \FTANGLE\ will also do the
  1623. right thing, spitting the main program out into a \.{FOR} file but the
  1624. \.{@<C code@>} into a \.{C} file. Furthermore, the modules
  1625. \.{@<Compute@>} and \.{@<Graph@>} will also be properly interpreted in~C, the
  1626. language that they inherit from \.{@<C code@>}.
  1627. ^^)example!program with two languages)
  1628. \vfill\Eject
  1629. \subsection Language commands in the definition part. 
  1630. ^^:language!of definition part:
  1631. \parinserto{2}{4}{0.4}
  1632. ``Identifiers also have language attributes.''
  1633. Language commands may also be inserted in the definition section, and are
  1634. sometimes necessary.  This situation arises because
  1635. identifiers also have language attributes;
  1636. ^^{identifiers!language attributes for} ^^{language!and identifiers}
  1637. this includes the special cases of reserved words and intrinsic functions,
  1638. and it implies that formats and outer macros (see below) are interpreted
  1639. according to one particular language. Although possibly a bit complicated,
  1640. this allows one to handle the important case where an identifier is 
  1641. a reserved word in one language but not in another.  For example,
  1642. \&{dimension} is a reserved word in \Fortran\ and \Ratfor, but not in~\C.
  1643. The only time when you have to worry about this explicitly is when you're
  1644. formatting a new identifier with~\atcmd{f}. (Formatting is explained below.)
  1645. You must be in the language in which you intend that identifier to be used.
  1646. This means you may have to switch languages in the definition section, even
  1647. if the identifier you're formatting is used in a named code section
  1648. immediately below whose language is already known. This is necessary because
  1649. modules start off in the global language and the language of the named
  1650. module isn't known until the module name is encountered,
  1651. \It{after} the definition section. Had one been thinking about multiple
  1652. languages when the \WEB\ system was first designed, he might have devised a
  1653. somewhat more elegant scheme, but it's too late now. In practice, the
  1654. present scheme does not seem to lead to too many annoyances.
  1655. Two built-in \WEB\ functions, \.{\_LANGUAGE} and \.{\_LANGUAGE\_NUM}, 
  1656. ^^{\>{\UL LANGUAGE}} ^^{\>{\UL LANGUAGE\UL NUM}}
  1657. are sometimes useful in writing conditional macros.  See the discussion
  1658. about built-in functions below for their definition.
  1659. The \WEB\ built-in function \.{\_LANGUAGE}  
  1660. (built-in functions are explained below)
  1661. expands to either `\.{\_C}', `\.{\_CPP}', `\.{\_N}',
  1662. `\.{\_N90}', `\.{\_R}', `\.{\_R90}', or~`\.{\_X}', depending on the
  1663. language currently in effect. 
  1664. ^^{\>{\UL C}} ^^{\>{\UL CPP}}
  1665. ^^{\>{\UL N}} ^^{\>{\UL N90}}
  1666. ^^{\>{\UL R}} ^^{\>{\UL R90}}
  1667. ^^{\>{\UL X}}
  1668. \dsubsection Optional arguments to language commands. ^^:arguments!optional:
  1669. \parinserto{2}{5}{0.6}
  1670. ``Language control codes may always be optionally followed by text enclosed
  1671. by square brackets.''
  1672. Some of the language commands may have optional arguments.  For example,
  1673. \Fortran--90 is treated as a dialect of the fundamental language~\Fortran.
  1674. It can be invoked by the commands~`\.{-n9}' or~\atcmd{n9}.  Here the
  1675. text~``\.{9}''~is the optional argument.  An other example of such a command
  1676. is~\atcmd{r9}, which sets the
  1677. language to \Ratfor--90.  The latter means that \Ratfor\ syntax is
  1678. understood along with \Fortran--90 keywords, \It{and} that the \Ratfor\ is
  1679. translated into \Fortran--90 rather than \Fortran--77.  All the possible
  1680. arguments relating to languages are detailed in the section below on
  1681. command-line options, and in Appendix~L.
  1682. The preceding examples are special cases of a more general mechanism.
  1683. Language control codes may always be optionally followed by text enclosed
  1684. by square brackets.  ^^[brackets, square] ^^[arguments!to language control
  1685. codes] 
  1686. One may put inside the square brackets (almost)
  1687. any option that may be put on the command line, allowing parameters to be
  1688. reset at each language change.  As a useful shorthand, if a language
  1689. control code is followed 
  1690. immediate by text (non-white space) that is not begun by a left bracket,
  1691. the text is automatically prefaced by a hyphen and the control code, then
  1692. enclosed by brackets. That is,
  1693.     \hbox{\.{@n}\It{text}} \equiv \hbox{\.{@n[-n\It{text}]}}
  1694. so we see, for example, that
  1695.     \hbox{\.{@n/}} \equiv \hbox{\.{@n[-n/]}}
  1696. (It may be interesting to know that \Cpp~is handled in this same
  1697. way---i.e., ``$\hbox{\.{@c++}} \equiv \hbox{\.{@c[-c++]}}$'', although one
  1698. will generally not need to be concerned with this.)
  1699. Parameters in force for a given language are saved when leaving that
  1700. language and restored when returning to it.  Thus, one can mix modules
  1701. with different dialects of \Fortran, as in
  1702. {\codemode
  1703. \Tab @<Fortran--90 stuff@>
  1704. \Tab .
  1705. \Tab .
  1706. \Tab @<Fortran--77 stuff@>
  1707. @ The code part of this section will be in the global language 
  1708. of Fortran--90.
  1709. @<Fortran--90...@>=
  1710. \Tab .
  1711. \Tab .
  1712. @ This section will be in Fortran--77.
  1713. @<Fortran--77...@>=
  1714. \Tab .
  1715. \Tab .
  1716. Although it would sometimes be convenient, one cannot at present use
  1717. shorthand such as~\atcmd{n9\&}; you must say \atcmd{n9[-n\&]}.  This
  1718. restriction is necessary because some arguments expect additional
  1719. characters to follow.  Thus, the form \atcmd{n9\&} is, according to the rules
  1720. above,  equivalent to \atcmd{n[-n9\&]}, so the ampersand would be
  1721. interpreted as an (invalid) subargument to ``\.{-n9}''.
  1722. Certain options such as macro definitions are forbidden as optional
  1723. parameters following a language code.  These are specified in Appendix~L.
  1724. The bottom line about languages is that if one uses only one, one needs to do
  1725. nothing more than place one language command somewhere in the limbo section.
  1726. If one mixes languages, one needs to place at least one additional language
  1727. command somewhere in the unnamed module; one has to be slightly more
  1728. alert, but not very much so. The intent is that languages should work the way
  1729. one expects them to, without having to do much of anything.
  1730. ^^)languages)
  1731. \dsection MACROS.[7.7] ^^(macros(
  1732. \parinserto{2}{4}{0.5}
  1733. ``Say `{\ssbf YES}' instead of `1', or `{\ssbf EPS}' instead of `1.0e-6'.''
  1734. Macro processing---definition of shorthand, readable symbols for otherwise
  1735. obscure, tedious, or repetitive constructions---is one of the most
  1736. effective ways to enhance one's coding productivity 
  1737. ^^[productivity!enhancing]
  1738. and the ultimate
  1739. readability of a code. For example, virtually no numerical constants should
  1740. appear explicitly in a well-written source code; they should be defined
  1741. symbolically in terms of macros instead. Say `\.{YES}' instead of~`\.1', or
  1742. `\.{EPS}' instead of \hbox{`\.{1.0e-6}'}. If later you decide that
  1743. $\epsilon$~should be~$10^{-7}$ instead of~$10^{-6}$, you need to change
  1744. just the single macro definition line rather than to edit many lines of the
  1745. source code; furthermore, a well-chosen symbolic name carries much more
  1746. meaning than a raw number. The C~language has a built-in preprocessor, and
  1747. that is one of the major virtues of~C.  Unfortunately, \Fortran\ lacks a
  1748. macro preprocessor. It does contain the
  1749. \&{parameter} statement. However, that statement is highly restrictive: its
  1750. scope is restricted to each individual subroutine, and arguments are not
  1751. allowed. Since often more flexible macro processing is useful, many people
  1752. adopt the strategy of running their 
  1753. \Fortran\ code through a preprocessor such as \Unix'~\.{m4}. ^^{\>{m4}}
  1754. This extra
  1755. processing step is annoying at the very least, and also requires one to
  1756. learn the syntax of the preprocessor. Although these steps cannot be
  1757. entirely avoided, their difficulty can be minimized. Thus, \FWEB\
  1758. has its own built-in macro preprocessor. This is patterned after
  1759. the ANSI C~preprocessor, ^^{preprocessor!ANSI C}
  1760. so that users who are either already familiar with~C or who are using
  1761. \FWEB\ to program in both~C and \Fortran\ are presented with a
  1762. syntax that is essentially language-independent. In practice, this turns
  1763. out to be an important consideration. The design and operation of the
  1764. C~preprocessor are also arguably more convenient than \.{m4} for many
  1765. applications, although this is certainly a matter of taste to some extent.
  1766. \dsubsection WEB macros.[7.1.12]
  1767. \parinserto{2}{4}{0.35}
  1768. {\ssbf WEB} macros are defined by `{\ssbf @m}'.
  1769. \WEB\ macros, sometimes called ``internal'' or ``inner'' macros,
  1770. ^^:macro!internal: ^^:macro!inner:
  1771. are defined by the command~\atcmd{m}. ^^{\>{@m}}
  1772. Temporarily, let us assume that these
  1773. definitions are made in the definition section (as they should always be,
  1774. except for special considerations described below).  In general, \WEB\
  1775. macros are expanded when the code is being \It{output} in phase two. \[The
  1776. exception to this is when a macro is encountered in a \WEB\ preprocessor
  1777. statement (beginning with~\atcmd{\#}; see below); then, it is expanded
  1778. immediately.\] As defined for ANSI~C, there are two macro forms:
  1779. ``object-like,'' and ``function-like.'' 
  1780. \subsubsection Object-like macros. ^^:macro!syntax!object-like:
  1781. ^^[syntax rules!\WEB\ macros]
  1782. Object-like macros have no arguments; they have the form
  1783. ^^:macro!object-like:
  1784. {\codemode
  1785. @m \Identifier\ \Replacementtext\ \Optcmnt
  1786. \noindent Here and elsewhere, \Replacementtext\ is an arbitrary string of
  1787. symbols (except that module names are not allowed). The \Replacementtext\
  1788. may be continued on subsequent lines.
  1789. ^^[macro!continuing]
  1790. Unlike the C~preprocessor, which
  1791. requires continued lines to end with a backslash, no backslashes are needed
  1792. (or allowed) for macros continued in the definition section. The reason for
  1793. this is that the end of the definition 
  1794. can be determined from the context; it occurs when the next definition
  1795. (\atcmd{m} or~\atcmd{d}), format command (\atcmd{f}), preprocessor
  1796. command~(\atcmd{\#}), limbo text command~(\atcmd{l}), operator overloading
  1797. command~(\atcmd{v}), identifier overloading command~(\atcmd{W}), unnamed
  1798. module command~(\atcmd{a}), module name~(\atcmd{<}), or new module command
  1799. (\atcmd{*} or~\atcmd{\ }) is encountered. The definition of \Identifier\ is
  1800. memorized during  phase one. Then, whenever the \Identifier\ is encountered
  1801. as the code text 
  1802. is being output in phase two, it is replaced by the \Replacementtext\
  1803. (which is then rescanned for further macro substitutions).
  1804. Simple examples of object-like macros are
  1805. ^^<macro!object-like>
  1806. {\codemode
  1807. @m NO 0 // An object-like macro (having no arguments).
  1808. @m YES 1 // It is conventional to use 1 for true, 0 for false.
  1809. @m PI 3.14159 // Most constants should be given readable symbolic names.
  1810. @m ARG_LIST x,kx,ky,kz
  1811. @m DCL_ARGS real x;
  1812. \Tab\Tab integer kx,ky,kz // Notice how easily this macro was continued.
  1813. @m BLANK // A null macro, with no replacement text.
  1814. Object-like macros are closely related, though not identical, to \Fortran's
  1815. \&{parameter} statement. ^^[statement!\<{parameter}]
  1816.     ^^{declarations!\<{parameter}} 
  1817. The differences are that a \WEB\ macro is known throughout the entire code
  1818. and will appear in expanded form in the tangled output, whereas a
  1819. \&{parameter} declaration is local to a subroutine and is expanded by the
  1820. \Fortran\ compiler, rather than by \TANGLE. This means that your tangled
  1821. output may be more readable if you use \&{parameter} statements instead of
  1822. \WEB\ macros. However, although this may be adequate in simple cases, it
  1823. will often not be a viable option. For example, to effectively use the
  1824. preprocessor facility to be described shortly one must use \WEB\ macros.
  1825. Furthermore, one can supply arguments to \WEB\ macros, a very useful
  1826. feature that we describe now.
  1827. \subsubsection Function-like macros. ^^:macro!syntax!function-like:
  1828. The syntax of function-like macros is
  1829. ^^:macro!function-like:
  1830. {\codemode
  1831. @m \Identifier(\Arglist) \Replacementtext\ \Optcmnt
  1832. \noindent The \Arglist\ is a comma-separated list of parameter names. (The
  1833. list may be empty.) If the \Arglist\ is terminated by an ellipsis
  1834. (\.{\dots}) instead of a parameter name, the macro is allowed to have a
  1835. variable number of arguments (unlike ANSI~C, which permits only macros with
  1836. a fixed number of arguments). 
  1837. In simple cases things work the way one would expect:
  1838. the actual arguments are determined and the parameters in the
  1839. \Replacementtext\ are replaced by those arguments. The general mechanism is
  1840. slightly complex and is explained below. First, however, here are simple
  1841. examples of function-like macros.  (In some of the examples to follow, the
  1842. result of the macro expansion is shown in a comment, enclosed by single
  1843. left and right quotes. These quotes are not to be confused with
  1844. \Fortran's character strings; they would not be part of the actual macro
  1845. expansion.)
  1846. ^^<macro!function-like>
  1847. {\codemode
  1848. @* FUNCTION-LIKE MACROS.
  1849. @m MULT(a,b) ((a)*(b)) // A macro with 2 args. $a$ and~$b$ are dummies.
  1850. @m EAT(x) // Gobble up the argument.
  1851. @f LOOP for
  1852. @m LOOP() do i=0,N;
  1853. \Tab do j=0,N
  1854. z = MULT(x-5,y); // Expands to `z = ((x-5)*(y));'.
  1855. if(z < 0.0) return NO; // Uses the object-like macro~|NO| defined above.
  1856. LOOP()
  1857. \Tab \{\dots\}
  1858. Several remarks can be made about the previous examples. First, a standard
  1859. remark:  the
  1860. parentheses in the replacement text of~\\{MULT} are absolutely essential;
  1861. consider what would have happened if \\a had not been parenthesized.
  1862. Second, one may ask why \\{LOOP} was defined as a function-like macro with
  1863. no arguments instead of as an object-like macro. \FTANGLE\ would create the
  1864. same expanded code in either case. However, it is useful to define things
  1865. as we did in order to help \FWEAVE\ format the macro properly. The format
  1866. command tells \FWEAVE\ to treat \\{LOOP} in the same way that it treats
  1867. \&{for}. In \Ratfor\ the keyword \&{for} expects a parenthesized expression
  1868. to follow; our definition of \\{LOOP} accomodates that. Thus, in the output
  1869. it will actually appear in boldface, and the body of the \&{LOOP} will be
  1870. properly indented.
  1871. \dsubsubsection Extensions to \WEB\ macro syntax.
  1872. ^^:macro!syntax!extensions to: ^^:extensions!to \WEB\ macro syntax:
  1873. There are two special (and partly experimental) variants of the
  1874. \atcmd{m}~command.  The construction~`\atcmd{m*\ \dots}' means that the
  1875. macros is allowed to be recursive. 
  1876. ^^{macro!recursive} 
  1877. \It{(However, recursive macros
  1878. are not implemented in the present version.)}  The construction
  1879. `\atcmd{m[\It{letters}]\ \dots}' says that this macro is associated with
  1880. ^{automatic insertion} material.  See the subsequent discussion of \Ratfor\
  1881. for more details.
  1882. \dsubsubsection Stringizing.
  1883. \parinserto{2}{5}{0.6}
  1884. ``Several special tokens beginning with `{\ssbf\#}' may appear in the
  1885. replacement text of \WEB\ macros.''
  1886. Several special tokens beginning with `\Stringize' may appear in the
  1887. replacement text of \WEB\ macros.  The most important of these are
  1888. `\Stringize' and `\Paste', which are borrowed from the ANSI C~preprocessor.
  1889. In the ANSI usage, the token `\Stringize' (``stringize'') ^^[stringizing]
  1890. must appear before a macro parameter (dummy argument). It and the parameter
  1891. will be replaced by a string literal (appropriate for the language in force
  1892. at the moment of expansion) constructed out of the corresponding actual
  1893. (unexpanded) argument. (In \Fortran, strings are delimited by single
  1894. quotes; in \Ratfor\ and~C, they are delimited by double quotes.)  For the
  1895. simplest possible example,
  1896. {\codemode
  1897. @* STRINGIZING.
  1898. @m S(s) #s
  1899. S(Hello); // Expands to `"Hello";'.
  1900. \Tab S(Hello) // In Fortran, the same macro expands to 'Hello'.
  1901. What happens when the argument to a stringize operation is already a
  1902. string? The answer, consistent with ANSI~C, is that the original quotes are
  1903. escaped appropriately and the whole thing is surrounded by quotes.
  1904. Therefore, \.{"hello"} stringizes to \.{"\\"hello\\""} in~C. This may not be
  1905. what you want; see the discussion of the \.{\#*}~operator below.
  1906. \dsubsubsection Making single- and double-quoted strings.
  1907. ^^:\>{\PM'}: ^^:\>{\PM""}:
  1908. If one stringizes a parameter in~C, the parameter will always be enclosed
  1909. in double quotes.  In cases involving manipulations of single characters,
  1910. one may instead desire single quotes.  To stringize a parameter and force
  1911. it to be enclosed in a particular kind of quote, use the \.{\#'} or
  1912. \.{\#"}~commands, which are extensions to~ANSI.  Thus, if in~C one defines
  1913. `\atcmd{m A(c) \#'c}', then ``\.{A(x)}''~expands to~``\.{'x'}''.  
  1914. \dsubsubsection Token pasting.
  1915. The token `\Paste' (``paste'')
  1916. ^^[pasting] ^^:\>{\PM\PM}:
  1917. merges together the things on
  1918. either side of it.  If possible, a new identifier is created.  For example,
  1919. $\hbox{\.{pas\paste te}}$~becomes the new identifier
  1920. $\hbox{\.{paste}}$; however, nothing effectively happens if one says
  1921. `$\hbox{\.{pas\#\#(}}$'. Note that the token-pasting operation can create new 
  1922. identifiers that may themselves be macros; these will be expanded when the
  1923. result is rescanned. For a  simple example,
  1924. ^^<pasting>
  1925. {\codemode
  1926. @* PASTING.
  1927. @m PASTE(a,b) a##b
  1928. @m paste 1
  1929. PASTE(pas,te) // Expands to `1'.
  1930. \dsubsubsection Macro expansion.
  1931. Macro expansion is intrinsically recursive, and one must be aware of the
  1932. order of expansion of various objects.  The complete expansion of a macro
  1933. proceeds through several steps.  The intent is that the procedure emulate
  1934. that of the ANSI~C preprocessor.
  1935. ^^[macro!expansion]
  1936. \parinsert{2}{4}{0.4}
  1937. ``Macro expansion is intrinsically recursive.''
  1938. First, the identifier is recognized and the expected number~$n$ of
  1939. arguments is determined.
  1940. ^^[macro!arguments]
  1941. If the identifier is object-like, a
  1942. parenthesized, comma-delimited list of actual arguments is expected (except
  1943. that if $n = 0$, there should be no arguments inside the parentheses). It
  1944. is an error if the parentheses aren't found or if the actual number of
  1945. arguments does not agree with the original definition. Within the
  1946. parentheses, commas protected by balanced parentheses do not count in
  1947. determining the end of the argument. Thus, the second argument to
  1948. the three-argument macro call `\.{MACRO(a,(b,c),d)}' is `\.{(b,c)}'.
  1949. Next, the replacement text associated with the macro is examined. If that
  1950. text contains instances of parameters preceded by `\Stringize', 
  1951. ^^{stringizing}
  1952. both `\Stringize' and the parameter are replaced by a string built out of the
  1953. actual argument (which is not expanded). If there are parameters preceded
  1954. or followed by `\Paste',
  1955. ^^{pasting}
  1956. those parameters are replaced by their corresponding actual arguments;
  1957. again, these arguments are \It{not expanded}.  Otherwise, parameters are
  1958. replaced by the actual arguments \It{after those arguments have been
  1959. exhaustively scanned for further macro expansions}.
  1960. After argument substitution, any paste operations are performed. Then
  1961. the result is rescanned for any further macros, which will be, in general,
  1962. expanded. Rescanning continues until nothing was expanded on the last pass.
  1963. For example, given the definitions
  1964. ^^<pasting> ^^<stringizing>
  1965. {\codemode
  1966. @m A 1
  1967. @m B 2
  1968. @m AB 3
  1969. @m C(a,b) a + a##b + #b
  1970. \noindent the macro call \.{C(A,B)} becomes after argument substitution and
  1971. pasting `\.{1 + AB + "B"}'; this is rescanned to yield the final result
  1972. `\.{1 + 3 + "B"}'. Note that macros inside strings are not expanded, and
  1973. that macro rescanning does not simplify numeric expressions such as $1+3$.
  1974. (Such simplifications can be accomplished by the \.{\_EVAL} built-in function
  1975. described below.)
  1976. In one important situation macros are not expanded. If a macro is being
  1977. expanded and its name is encountered again during that expansion, then it
  1978. is not expanded. This prevents various kinds of infinite recursion, 
  1979. ^^[macro!recursion]
  1980. the simplest candidate being \atcmd{m A A}---this expands to `\.{A}', not an
  1981. infinite loop. Also, consider the previous example of \.{PASTE(a,b)} and
  1982. experiment to find out what happens when you say `\.{PASTE(PAS,TE)}'. (This
  1983. construction is illegal.)
  1984. ^^<stringizing> ^^<pasting>
  1985. {\codemode
  1986. @ Here are further examples of stringizing and token-pasting:
  1987. @m P(s) #s = s // Displays the result of a macro expansion.
  1988. @m VAR(i) var##i // Makes a new identifier name.
  1989. @m RECURSE(a,b) a##b(a,b) // Possibility for recursion here.
  1990. @m X 1
  1991. @m Y 2
  1992. @m Z ZZ
  1993. @m XY Z
  1994. P(VAR(2)) // -> `"VAR(2)"=var2'
  1995. P(RECURSE(X,Y)) // -> `"RECURSE(X,Y)"=ZZ(1,2)'
  1996. P(RECURSE(RE,CURSE)) // -> `"RECURSE(RE,CURSE)"=RECURSE(RE,CURSE)'
  1997. \noindent Note that the last example did not get hung in an infinite loop.
  1998. ^^(macro!extensions( ^^[extensions!to ANSI C macro syntax]
  1999. The macro facilities that have been described so far are intended to
  2000. emulate those of ANSI~C. A wide variety of tasks can be accomplished with
  2001. them.  Although in the following paragraphs we describe various \FWEB\
  2002. extensions to the ANSI~C preprocessor, \It{it is recommended that you
  2003. employ these only as a last resort}. The sparser the constructions and
  2004. features that you deal with, the less likelihood there will be for
  2005. programming errors.
  2006. \vfill\Eject
  2007. \subsubsection Including a comma in a macro argument.
  2008. \parinserto{1}{3}{0.6}
  2009. To include a comma in a macro argument, use the `{\ssbf \#,}' token. 
  2010. Since the arguments of macros are delimited by commas, it is not
  2011. immediately apparent how to
  2012. introduce a comma as part of a macro argument.  To do so, use the
  2013. `\.{\#,}'~token.  
  2014. ^^:\>{\PM,}:
  2015. ^^{commas!as delimiters of macro arguments}
  2016. ^^{commas!as part of a macro argument}
  2017. For example,
  2018. {\codemode
  2019. @m A(x,y) [x][y]
  2020. @m B(x) A(x)
  2021. B(3#,2) // -> `[3][2]'
  2022. \noindent Had one tried here to say ``\.{B(3,2)}'', he would have elicited
  2023. an error message, since \.{B}~is defined with only one argument.  
  2024. \subsubsection Concatenating strings.
  2025. \parinserto{1}{4}{0.55}
  2026. The {\ssbf FWEB} macro preprocessor concatenates adjacent strings.
  2027. In ANSI~C, adjacent strings, possibly separated by white space, are
  2028. concatenated on input.  Thus,  ``\.{"a"\ "bc"}'' is equivalent
  2029. to~``\.{"abc"}''.  \FWEB\ does not do such concatenation when reading \WEB\
  2030. source code; however, the \FWEB\ macro preprocessor does do so.  Thus, the
  2031. expansion of the macro definition `\atcmd{m\ A\ "1""23"}' will
  2032. be~``\.{123}''.  This facility is useful because the preprocessor does not
  2033. expand macros inside quoted strings.  Thus, with
  2034. {\codemode
  2035. @m PW sexylady
  2036. @m MSG "The password is '"_STRING(PW)"'."
  2037. \noindent \\{MSG}~expands into ``\.{"The password is 'sexylady'."}''.  This
  2038. feature should be particularly useful in \Fortran\ or \Ratfor\ for easily
  2039. constructing readable error messages.
  2040. \dsubsubsection Quoting macros.
  2041. In some situations, it is desirable to prevent a macro from being expanded.
  2042. Enclosing a macro with special characters to prevent expansion is sometimes
  2043. called ``quoting'' the macro.
  2044. ^^:macro!quoting: ^^{macro!preventing expansion of}
  2045. In other preprocessors such as \.{m4}, often
  2046. left and right square brackets are used to prevent expansion; each time a
  2047. pair of brackets is encountered, the outer brackets are stripped off. For
  2048. example, with the definition \atcmd{m N 10} the \Fortran\ source statement
  2049. `\.{[N] = N}' would expand to `\.{N = 10}'.  The \.{m4} preprocessor
  2050. provides the \&{changequote} command ^^{\<{changequote}}
  2051. to set the quoting characters. No such
  2052. quoting facility exists in ANSI~C, and experience shows that one is
  2053. generally better off without it. For example, the previous example is
  2054. better handled with the facilities of \FWEB\
  2055. by recalling that the macro processor is case-sensitive
  2056. while \Fortran\ is not, so one could simply say `\.{n = N}'.  However, in a
  2057. few situations quoting is necessary or convenient. For example, it is
  2058. difficult to include a comma unprotected by parentheses in a macro argument
  2059. without quoting it. Unfortunately, the number of special characters
  2060. available in \FWEB\ as candidates for quote characters is severely limited;
  2061. C~has usurped almost all of them (including brackets, in particular) for
  2062. its own purposes. Presently, in \FWEB\ one level of quoting can be
  2063. accomplished by 
  2064. enclosing the text that is not to be expanded with left single
  2065. quotes---for example, `\.{`N` = N}'. (This style of programming is
  2066. definitely not recommended.)  As another example, consider a C~example that
  2067. aborts by printing the name of a buffer that was overrun by a string print
  2068. operation.  The example defines a three-argument macro \.{SPRINTF}, whose
  2069. last argument is intended to actually be a comma-delimited \It{list} of
  2070. arguments.  Left quotes can be used to force that list to be treated as one
  2071. argument (although see the discussion of variable arguments below for a
  2072. better way).  The example also illustrates the stringizing operation and an 
  2073. appropriate usage of outer macros (explained below) vs.\ \WEB\ macros.
  2074. ^^<macro!quoting>
  2075. {\codemode
  2076. @d N 1000
  2077. @m SPRINTF(buf_name,nmax,args) 
  2078. \Tab if(sprintf(buf_name,args) >= nmax) overflow(#buf_name)
  2079. char temp[N];
  2080. SPRINTF(temp,N,`"x = 0.2e\\n",x`);
  2081. \noindent In general, if you encounter a situation in which you think you
  2082. need to quote something, pause and think again; very often there's a better
  2083. way. 
  2084. \dsubsubsection Passing quoted strings unchanged through stringize.
  2085. As noted, when the single token `\Stringize' is followed by a macro
  2086. parameter, the parameter is made into a string. When `\Stringize' is
  2087. followed by something other than a macro parameter, other actions are
  2088. taken by \FWEB.
  2089. Sometimes you would like an existing quoted string to be
  2090. passed unchanged through the stringize operation. This can be accomplished
  2091. with the \.{\#*} operator.
  2092. ^^:\>{\PM *}:
  2093. Thus, consider
  2094. {\codemode
  2095. @* STRINGIZING REDUX.
  2096. @m S(s) #s
  2097. @m T(s) #*s
  2098. S("hello"); // -> `"\\"hello\\"";'.
  2099. T("hello"); // -> `"hello";'.
  2100.     S('hello') // -> '''hello'''.
  2101.     T('hello') // -> 'hello'.
  2102. \dsubsubsection Automatic statement numbering.
  2103. \parinserto{2}{4}{0.5}
  2104. ``Numeric statement labels are unreadable anachronisms.''
  2105. For \Fortran\ programmers, 
  2106. the most important of the extensions is related to automatic statement
  2107. numbering.
  2108. ^^[statement!numbering]
  2109. ^^[Fortran:\FORTRAN!automatic statement numbering]
  2110. There are two distinct
  2111. possibilities, both begun by `\.{\#:}'.  ^^{\>{\PM":}}
  2112. The construction
  2113. `\.{\Stringize:0}' expands \It{at the time the definition is being stored}
  2114. (in phase one) to a unique statement number. That same number will be used
  2115. in all expansions of that macro throughout the program. Thus, it is
  2116. possible to completely abandon numeric statement labels in \Fortran\ simply
  2117. by ``declaring'' alphanumeric labels as \WEB\ macros, as in the following
  2118. example:
  2119. {\codemode
  2120. @* STATEMENT LABELS.
  2121. @m START #:0
  2122. @m DONE #:0
  2123. \Tab program main
  2124. START: continue
  2125. DONE: end
  2126. \noindent Note that alphanumeric labels must be followed by a colon, just
  2127. as in~C.  If you are a \Fortran\ programmer, \It{it is strongly encouraged
  2128. that you make use of this mechanism.} Numeric statement labels are an
  2129. unreadable anachronism.
  2130. If `\.{\Stringize:}' is followed by a positive integer~$n$, it expands into
  2131. a unique statement number (the current automatic statement number plus~$n$)
  2132. \It{at the time the macro is being expanded} (in phase
  2133. two). That number can appear more than once in the macro's replacement
  2134. text. It will expand into the same statement number during a given
  2135. expansion of the macro, but will generate a different unique number in each
  2136. subsequent expansion. This feature is useful in defining macros such as
  2137. error procedures that contain labelled code. For example,
  2138. ^^<statement!numbering>
  2139. {\codemode
  2140. @m CHECK(i,err_num) if(i >= 0) goto #:1;
  2141. \Tab\Tab call errprint(err_num);
  2142. \Tab\Tab\Tab return;
  2143. \Tab #:1 continue@;
  2144. \noindent (Of course, this particular example could have been accomplished
  2145. without statement numbers at all by using an \&{if}\dots\&{end if}
  2146. construction.) 
  2147. The starting value~\It{nnnnn} of the automatic statement number can be
  2148. set by the command-line option \hbox{`\.{-:\It{nnnnn}}'}.
  2149. ^^{\>{-":}} ^^[statement!number!setting]
  2150. Any user statement
  2151. number must be less than that value. (\FWEB\ does not check that this
  2152. restriction is obeyed.)
  2153. Again, proper use of the `\.{\#:0}' and
  2154. `\.{\PM :}$n$' options should entirely eliminate the need for
  2155. explictly-defined user statement numbers in \Fortran.  \It{Note:}
  2156. Automatic statement numbers are not intended to replace \&{if}-, \&{case}-,
  2157. or~\&{do}-construct names in \Fortran--90.  For example, in the legitimate
  2158. \Fortran--90 construction
  2159. {\codemode
  2160. iterate: do
  2161. \Tab ...
  2162. end do iterate
  2163. \noindent the label \\{iterate} should not be declared as an automatic
  2164. statement number.
  2165. \dsubsubsection Preventing macro expansion.
  2166. Next, we have the ``don't expand'' option `\.{\#!}'.
  2167. ^^:\>{\PM"!}: ^^[macro!preventing expansion of]
  2168. As stated earlier, usually
  2169. actual macro arguments are exhaustively expanded before they are
  2170. substituted into macro replacement text. To prevent this, preface a macro
  2171. parameter by `\.{\#!}'. Consider, for example,
  2172. ^^<macro!preventing expansion of>
  2173. {\codemode
  2174. @* PREVENTING MACRO EXPANSION.
  2175. @m A 1
  2176. @m S(s) #s
  2177. @m R(expr) S(expr)
  2178. @m Q(expr) S(#!expr)
  2179. S(A) // -> `"1"'
  2180. R(A) // -> `S(1)' -> `"1"'
  2181. Q(A) // -> `S(A)' -> `"A"'
  2182. ^^)macro!extensions)
  2183. \dsubsubsection Module names in macro definitions.
  2184. Occasionally one may want to include a module name as part of a macro
  2185. definition. The original design of \WEB\ precluded this possibility, since
  2186. encountering an \atcmd{<}~construction while in the definition section
  2187. signaled the start of a named code section. Therefore, within a macro
  2188. definition the special construction \.{\#<\dots@>} ^^{\>{\PM<...@>}}
  2189. may be used to represent a module name. Thus, you can make definitions such as
  2190. {\codemode
  2191. @m SHORTHAND #<First stuff@>@; #<Last stuff@>
  2192. \noindent Of course, you lose the readability of the module names in the
  2193. code proper if you do
  2194. things this way. Generally, the module name would be only a small part of a
  2195. much longer macro definition.
  2196. \dsubsubsection Macros with variable numbers of arguments.
  2197. ^^[arguments!variable, in macros] ^^[macro!arguments!variable number of]
  2198. \parinserto{1}{4}{0.6}
  2199. {\ssbf WEB} macros may have a variable number of arguments.
  2200. We now discuss macros with variable numbers of arguments. These are
  2201. indicated by an argument list that ends with an ellipsis (\.{...}).
  2202. ^^{ellipsis "(\noexpand\dots")} ^^{\>{...} "(ellipsis")}
  2203. Certain built-in functions such as
  2204. \\{\_IFCASE} accept a variable number of arguments. You can also define
  2205. them yourself, using some special tokens beginning with~'\.{\#}' to help.
  2206. The construction~`\.{\#0}' ^^:\>{\PM0}:
  2207. expands into the number of variable arguments (those arguments that replace
  2208. the ellipsis).  Note that an empty argument ^^{macro!arguments!empty}
  2209. is not the same as no arguments.  For example, \.{\#0}~counts as follows:
  2210. {\codemode
  2211. @m A(...) #0
  2212. A => 0
  2213. A(x) => 1
  2214. A() => 1
  2215. A(x,y) => 2
  2216. A(x,) => 2
  2217. A(,y) => 2
  2218. A(,) => 2
  2219. The construction~`\.{\#$n$}', where $n > 0$, ^^:\>{\PM}$n$:
  2220. expands into the $n^{\rm th}$ variable argument (counting from~1).  
  2221. The constructions~`\.{\#\{0\}}' and~`\.{\#\{$n$\}}' are just like~`\.{\#0}'
  2222. and~`\.{\#$n$}' except that the argument inside the braces may be an macro
  2223. expression [anything that you could put inside \.{@\#if(\dots)}] that is
  2224. known at output time.  This is often useful in conjunction with the
  2225. \.{\_DO} built-in macro.  For example,
  2226. {\codemode
  2227. @m BFORALL(nmin,nmax,mmin,mmax,...) 
  2228. \Tab    forall(i=nmin:nmax,j=mmin:mmax) #\{I\}(i,j) = #\{I+1\}(j,i)
  2229. _DO(I,1,6,2)
  2230. \Tab \{
  2231. \Tab BFORALL(1,5,0,20,v1,v2,v3,v4,v5,v6)
  2232. \Tab \}
  2233. The construction~`\.{\#[0]}' is just like~`\.{\#\{0\}}' except that it
  2234. counts the fixed arguments as well.  The construction~`\.{\#[$n$]}' is just
  2235. like~`\.{\#\{$n$\}}' except that the counting begins with the first fixed
  2236. argument.  Thus, in the above call to \\{BFORALL}, one has $\.{\#0} = 6$,
  2237. $\.{\#\{0\}} = 6$, $\.{\#[0]} = 10$, $\.{\#[2]} = 5$, and $\.{\#[6]} =
  2238. \.{\#\{2\}} = \.{v2}$. 
  2239. Finally, the construction~`\.{\#.}' ^^:\>{\PM.}:
  2240. expands into a comma-separated list of all the variable arguments.  
  2241. As examples,
  2242. {\codemode
  2243. @m V(x,y,...) x + y + f(#0,#.) + #3
  2244. @m V1(x,y,...) x + y _IFCASE(#0,,+g(#.))
  2245. V(a,b,x1,x2,x3) => a + b + f(3,x1,x2,x3) + x3
  2246. V1(a,b) => a + b
  2247. V1(a,b,c) => a + b + g(c)
  2248. \noindent The \\{V1}~example shows that the conditional builtins can often
  2249. be used to advantage in conjunction with variable arguments.
  2250. We can use variable arguments to reconsider the previous example of the
  2251. \.{SPRINTF} macro:
  2252. {\codemode
  2253. @m SPRINTF(buf_name,nmax,...)
  2254. \Tab if(sprintf(buf_name,#.) >= nmax) overflow(#buf_name)
  2255. char temp[N];
  2256. SPRINTF(temp,N,"x = 0.2e, y = 0.2g\\n",x,y); // 2 fixed args, 3 variable ones.
  2257. \noindent This works just fine.  However, a special feature of this example
  2258. is that valid syntax demands that there be at least one variable argument
  2259. (the string template).  Suppose instead we had defined
  2260. {\codemode
  2261. @m SPRINTF(buf_name,nmax,strng,...)
  2262. \Tab if(sprintf(buf_name,strng,#.) >= nmax) overflow(#buf_name)
  2263. \noindent Now there's potential difficulty when there are no variable
  2264. arguments.  For example, one might expect ``\.{SPRINTF(temp,N,"hello")}''
  2265. to expand to ``\.{if(sprintf(temp,"hello",) \dots}''; however, the missing
  2266. argument is invalid C~syntax.  Since this kind of construction seems to
  2267. arise fairly frequently, we have the following special \It{experimental}
  2268. rule: \It{if \.{\#.}~is empty and it immediately follows a comma in the
  2269. macro expansion, the comma is deleted.}  (Whether this is a good idea
  2270. remains to be seen. More elaborate alternatives are possible; complain if
  2271. you don't like this.) 
  2272. \dsubsubsection Debugging macros.
  2273. ^^[macro!debugging]
  2274. If one wishes to debug an errant macro, there are several possibilities.
  2275. First, one could simply dump its current expansion into the output file.
  2276. For example,
  2277. {\codemode
  2278. @m DUMP(...) [#.]
  2279. DUMP(A,B(1),C(x,y,z))
  2280. \noindent writes a comma-separated list of the expansions of three macro
  2281. calls, surrounded by brackets.  Alternatively, one can write information to
  2282. the terminal with the built-in function \.{\_DUMPDEF}.  The format is the
  2283. same as above; just replace \.{DUMP} by \.{\_DUMPDEF}.  For each macro call
  2284. in its argument list, \.{\_DUMPDEF} writes two lines.  The first is a
  2285. representation of the original macro definition; the second is its current
  2286. expansion.
  2287. \dsubsection Outer macros.
  2288. ^^[macro!expansion!deferring]
  2289. \parinserto{2}{5}{0.45}
  2290. To defer macro expansion to an external preprocessor, use the `{\ssbf @d}'
  2291. command.
  2292. As we have said, \WEB\ macros are expanded by \TANGLE\ as it creates the
  2293. compilable output file during phase two. This means that the output file,
  2294. which is what you will actually be debugging, need not be very readable if
  2295. the macros were at all sophisticated (and, therefore, very useful). For
  2296. \Fortran\ programming, one has no choice. However, for C~programming it is
  2297. desirable to defer macro expansion to the C~preprocessor so that your
  2298. output file remains readable.  This can, of course, be done with no special
  2299. effort just by using the C~preprocessor \.{\#define} command ^^{\>{\PM define}}
  2300. as part of your code fragment. Usually, you should insert these in the code
  2301. section of the module in which they are first used so that the flow of the
  2302. logic is clearest.  However, what you usually really want is for your
  2303. preprocessor definitions to appear at the top of your file, no matter where
  2304. you actually defined them. (There are exceptions to this.) To help you
  2305. achieve this effect while maintaining logical clarity, the \WEB\ system
  2306. supports the concept of ``\It{outer macros}''. ^^:macro!outer:
  2307. These are defined by the command~\atcmd{d}, ^^{\>{@d}}
  2308. which is allowed in the definition section only. \WEB\ does not expand
  2309. these; rather, it just collects them and copies them at the start of phase
  2310. two to the beginning of the output file in a format appropriate for the
  2311. relevant language compiler.  For symmetry, the command~\atcmd{u} ^^{\>{@u}}
  2312. is also provided to undefine an outer macro.  
  2313. The format of outer macros depends on the language in force. If the current
  2314. language is~C, the outer macros should, of course, be in the format
  2315. appropriate to the C~preprocessor; an outer C~definition of the form
  2316. \atcmd{d A 1} will appear in the beginning of the C~output file as
  2317. `\.{\#define A 1}'.  Otherwise, the outer macro should be in the format
  2318. appropriate to the 
  2319. \.{m4}~preprocessor. In languages other than~C, the definition 
  2320. \atcmd{d (B,2)} will appear in the beginning of the output file as 
  2321. `\.{define(B,2)}'. (With the advent of \FWEB's macro processor, the need
  2322. for outer macro definitions in languages other than~C should virtually
  2323. disappear.)
  2324. For example, when the language is~C, the statements
  2325. {\codemode
  2326. @d A 1
  2327. @d B 2
  2328. @d A 2
  2329. \noindent will be output as follows:
  2330. {\codemode
  2331. #define A 1
  2332. #define B 2
  2333. #undef A
  2334. #define A 2
  2335. A C~program maintained with
  2336. \WEB\ should almost exclusively contain the outer macro,
  2337. \atcmd{d}~commands. The 
  2338. internal, \atcmd{m}~commands should be used only when the \WEB\ system
  2339. provides a 
  2340. macro feature not included in the C~preprocessor.  Those features mostly
  2341. include stringizing and token pasting (included in the ANSI C~standard, but
  2342. not in many extant compilers). If you are using an ANSI C~compiler, your
  2343. need for \WEB\ macros will be slight, although a few of the extensions such
  2344. as~\.{\#!} or variable arguments may prove useful.
  2345. \dsubsection Deferred macros.
  2346. Returning now to the internal \WEB\ macros, their order of evaluation
  2347. ^^[macros!order of evaluation]
  2348. requires further discussion. It is important to understand that \It{all}
  2349. text, including macro definitions, is collected, tokenized, and stored
  2350. during \TANGLE's phase one. ^^{phase!1!\>{TANGLE}}
  2351. However, with certain exceptions (involving
  2352. the preprocessor) to be described, \It{no macros are actually expanded
  2353. during phase one}. The reason for this is that the actual source text in
  2354. which the macros are embedded and on which they must operate is not known
  2355. until all the text has been collected and placed into the proper modules.
  2356. Therefore, it is during phase two, when the completed code text is output,
  2357. that macros are expanded. However, in the original design of \WEB\ this led
  2358. to an annoying difficulty---namely, \WEB\ macro definitions could be
  2359. \It{retroactive}. 
  2360. ^^[macro!retroactive definition of]
  2361. The situation arises as follows.  In the original design, macros were
  2362. allowed only in the definition section of a module. Since all such macros
  2363. definitions are collected during phase one, they are all known by the time
  2364. code is output during phase two.  (Effectively, they are all placed at the
  2365. top of the unnamed module.)  Thus, a definition made in the definition
  2366. section of, say, module~100 could lead to a macro being expanded in module~1
  2367. if the code in module~1 contained a reference to that macro name. Although
  2368. this is usually the desired effect, it may not be in all cases. 
  2369. Consider, for example, the following example (see the discussion of
  2370. preprocessor commands, below):
  2371. {\codemode
  2372. @ Here is a peculiar example of retroactive macro definition.
  2373. @m A 1
  2374. \If(A==1)
  2375. \Tab x = A;
  2376. \Else
  2377. \Tab x = B;
  2378. \Endif
  2379. @ Another section.
  2380. @m A 2
  2381. \noindent Here the generated code will be ``\.{x = 2;}'', not ``\.{x = 1}'' or
  2382. ``\.{x = B;}''.  Note also that since the sections, hence the definition
  2383. parts, are not required to appear in any particular order, 
  2384. the order of encountering \WEB\ macro definitions is somewhat indefinite.
  2385. This can lead to confusion and hard-to-understand bugs if macros are
  2386. redefined and sections are subsequently moved around.
  2387. \parinsert{6}{5}{0.5}
  2388. Don't define {\ssbf WEB} macros in the code part unless you absolutely
  2389. have to.
  2390. For complete flexibility, therefore,  \FWEB\ introduces the
  2391. notion of \It{deferred macros}. ^^:macro!deferred:
  2392. Deferred macros are nothing more than \WEB\ macros defined (again
  2393. with~\atcmd{m}) in the \It{code} section rather than in the definition section. A deferred macro definition, although it is stored away in a safe place
  2394. during phase one, becomes known to the \WEB\ macro processor only at the point
  2395. in the code where the definition is made, when the code is being output
  2396. during phase two.  Thus, the order in which the deferred macro definition
  2397. is made is unambiguous (it is determined by the intrinsic structure of the
  2398. code, not by the order in which things were explained) and the deferred
  2399. definition cannot be inadvertently expanded retroactively.  Remembering the
  2400. previous discussion of C~preprocessing, we see a complete analogy: deferred
  2401. \WEB\ macros are analogous to the use in~C of
  2402. \.{\#define}; both are used in the code section. All definitions made in
  2403. the definition part behave similarly in that they are placed at the
  2404. beginning of the appropriate place: outer macro definitions (\atcmd{d}) are
  2405. placed at the beginning of the output file; \WEB\ macro definitions in the
  2406. definition part (\atcmd{m}) are effectively placed at the beginning of the
  2407. unnamed module. 
  2408. Most of the time, it will be adequate to define a \WEB\ macro in the
  2409. definition part, thereby placing it at the beginning of the unnamed
  2410. module, and it is recommended that you do so whenever possible. Reserve
  2411. deferred macro definitions for those relatively rare instances when the
  2412. order of defining the macro really does matter.
  2413. Although deferred \.{@m}~commands work as specified, presently
  2414. preprocessor commands (see below) such as~\.{@\#if} or~\.{@\#undef} do not
  2415. work as one might expect when referring to deferred macros. Presently, such
  2416. commands are executed during phase one (on input), whereas the deferred
  2417. macros become known only during phase two (on output).  Luckily, there is
  2418. an an alternative way of handling preprocessing during output, namely to
  2419. use built-in functions such as \.{\_IF}.
  2420. ^^{\>{\UL IF}}
  2421. See the discussion of built-ins below.
  2422. \dsubsection Language dependence of macros.
  2423. \WEB\ macros are by and large not sensitive to language when they are being
  2424. memorized, and with a few exceptions they will expand in the same way no
  2425. matter what language is current during output. (An example of an exception
  2426. is the behavior of the stringizing operation, which must build a string
  2427. using either a single or double quote depending on the language. Another
  2428. example is the \.{\_ROUTINE} built-in function ^^{\>{\UL ROUTINE}}
  2429. which at presently is defined only for
  2430. \Ratfor.)  Generally such uniform expansion is desirable. For example,
  2431. here is how one can supply a macro definition in~C and a \&{parameter}
  2432. statement in
  2433. \Fortran\ with a common value:
  2434. {\codemode
  2435. @ Web macros are known to all languages.
  2436. @m NN 100 // One can affect all languages by changing this one number.
  2437. @d N NN
  2438. \Tab parameter(N=NN) // A fragment of a Fortran code.
  2439. @<C functions@>@;
  2440. @ A simple C routine.
  2441. @<C...@>=
  2442. return N;
  2443. \noindent If language-sensitive behavior is desired, it can be achieved by
  2444. using the \.{\_LANGUAGE} built-in function ^^{\>{\UL LANGUAGE}}
  2445. in conjunction with an \.{\_IFELSE}, or the \.{\_LANGUAGE\_NUM} built-in
  2446. ^^{\>{\UL LANGUAGE\UL NUM}} in conjunction with an \.{\_IFCASE}. See further
  2447. discussion below. 
  2448. \parinsert{2}{5}{0.45}
  2449. {\ssbf WEB} macros can be defined from the command line with the option
  2450. `{\ssbf -m}'.
  2451. \WEB\ macros can also be defined from the command line by using the
  2452. command-line option `\.{-m}'. ^^:\>{-m}:
  2453. (See the detailed explanation in the section about command-line options.)
  2454. Command-line macros are processed at the beginning of the first definition
  2455. section. Defining macros from the command line is an efficient way to
  2456. customize a code without re-editing it. For example, you can supply fixed
  2457. array bounds to a \Fortran\ program employing one of the two equivalent
  2458. statements 
  2459. ^^<\>{-m}>
  2460. {\codemode
  2461. FTANGLE test -mN=1000
  2462. FTANGLE test -m"N 1000"
  2463. \noindent which is equivalent to saying \atcmd{m N 1000} at the beginning of
  2464. the first definition section,
  2465. then including statements such as `\.{integer x(0:N)}' in your code. 
  2466. The facility is
  2467. particularly useful in conjunction with the \FWEB\ preprocessor, to be
  2468. described next. 
  2469. ^^)macros)
  2470. \vfill\Eject
  2471. \dsubsection Preprocessing. ^^(preprocessing( ^^(preprocessor!\FWEB(
  2472. ^^[language!preprocessing] ^^[macro!preprocessing]
  2473. A common situation arises when one is designing a code to run on more than
  2474. one machine. One might want to define a macro with machine-dependent
  2475. values, or one might want to selectively include one or another piece of
  2476. code.  In addition to macro definitions, \WEB\ has a complete preprocessing
  2477. language to help in this respect.
  2478. \parinsert{1}{5}{0.4}
  2479. ``The {\ssbf WEB} preprocessor is patterned after that for ANSI~C.''
  2480. The \WEB\ preprocessor is patterned after that for ANSI~\C. All
  2481. preprocessing commands begin with~`\.{\PR}'. As in ANSI~C, they need not,
  2482. in general, begin in in column~1 (they must do so, at present, in \Fortran's
  2483. fixed-format mode). Unlike
  2484. ANSI~C, 
  2485. however, there may be no white space between~`\.{\PR}' and the command
  2486. name.  (\WEB\ interprets an isolated~`\.{\PR}' as a command to insert a blank
  2487. line.)  In~C and
  2488. \Ratfor\ they may be continued to subsequent lines by using a backslash; in
  2489. \Fortran, they are presently restricted to
  2490. end on the same line (including any optional comment). They are
  2491. {\narrower\parskip=0pt\medbreak\obeylines
  2492. \Define\ \It{macro\_name} \It{replacement\_text} 
  2493. \Undef\ \It{macro\_name} 
  2494. \Ifdef\ \It{macro\_name}
  2495. \Ifndef\ \It{macro\_name}
  2496. \If\ \It{expression}
  2497. \Elif\ \It{expression}
  2498. \Else
  2499. \Endif
  2500. \noindent The `\Define' command ^^:\>{@\PM define}:
  2501. is entirely equivalent to~\atcmd{m}. One can undefine a macro definition
  2502. with `\Undef'. ^^:\>{@\PM undef}:
  2503. (All previous definitions are completely lost; definitions
  2504. are not stacked.)  `\Ifdef' and `\Ifndef' test whether a macro is or is not
  2505. defined. ^^:\>{@\PM ifdef}: ^^:\>{@\PM ifndef}:
  2506. (These commands are special cases of~`\.{\If}'; see the discussion
  2507. of the `\.{defined}' operator below.) The
  2508. `\If\dots\Elif\dots\Else\dots\Endif' construction 
  2509. ^^:\>{@\PM if}: ^^:\>{@\PM elif}: ^^:\>{@\PM else}: ^^:\>{@\PM endif}:
  2510. evaluates
  2511. \It{expression}, which must consist of symbols known to the preprocessor at
  2512. the current point of the input scan, then takes action depending
  2513. on whether \It{expression} ^^{expression!logical}
  2514. is true (nonzero) or false~(0).  All
  2515. preprocessing commands may appear in either the definition part or the
  2516. code part. In the definition part, \FTANGLE\ will not process macro
  2517. definitions that are between the false part of the preprocessor
  2518. conditionals.  In the code part, \FTANGLE\ will not store or output code
  2519. that is between the false part. The conditionals may be nested.\filbreak
  2520. \It{Note that all preprocessor commands, including in particular those in
  2521. the code section, are expanded during phase one.}
  2522. ^^{phase!1}
  2523. This is a design flaw (maybe it will be corrected someday) that
  2524. means that the preprocessor commands will not work correctly with deferred
  2525. macros, 
  2526. ^^{macro!deferred}
  2527. which become known only during phase two. ^^{phase!2}
  2528. If you need to use
  2529. deferred macros with preprocessor commands, use the built-in forms of the
  2530. preprocessor commands such as \.{\_IF}. Built-ins are discussed below.
  2531. Use of the \WEB\ preprocessor is entirely analogous to that of~C. If you
  2532. are a C~programmer, you will need the \WEB\ preprocessor commands
  2533. relatively rarely; operations on your source code are usually better done
  2534. with the C~preprocessor. If you are a \Fortran\ programmer, however, you
  2535. should find the preprocessor facility extremely useful.
  2536. It is conventional to end long preprocessor constructions as follows, to
  2537. enhance the quality of the documentation:
  2538. {\codemode
  2539. @#if(CRAY)
  2540. \dots
  2541. @#endif // |CRAY|
  2542. \vfill\Eject
  2543. ^^[expression!evaluation]
  2544. \dsubsection Expression evaluation. ^^{macro!expression evaluation}
  2545. The \It{expression} in constructions such as \If~\It{expression} is
  2546. evaluated by a built-in expression evaluator that can also be used for
  2547. other purposes, such as in macro expansion.  Its behavior is again
  2548. motivated by expression 
  2549. evaluation in ANSI~C; it is not quite as general, but should be more than
  2550. adequate. It supports both integer and floating-point arithmetic (with type
  2551. promotion from integer to floating-point if necessary), and the ANSI
  2552. `\.{defined}' operator. Operators with the highest precedence 
  2553. ^^{operators!precedence of}
  2554. (see table below) are evaluated first; as usual, parentheses override the
  2555. natural order of evaluation. The unary operator `\.{defined}' 
  2556. ^^{\<{defined}, as unary operator}
  2557. has the highest
  2558. precedence; all the other unary operators have the next highest (and equal)
  2559. precedence; then come the binary operators. When the operator exists in~C,
  2560. the action taken by \FWEB\ is precisely that that the C~compiler would take.
  2561. Arithmetic is done in either \&{long} or \&{double} variables, as
  2562. implemented by the C~compiler that compiled \.{FTANGLE}.  (This was the
  2563. easy choice, not necessarily the most desirable one.)
  2564. ^^[expression!operators] ^^[operators]
  2565. The operators, listed from  highest precedence  to lowest, are as follows:
  2566. $$\def\<{{\rm ,$\,$}}
  2567. \def\mod{\Mathop{mod}}
  2568. \vtop{\halign{\tt\quad#\quad\hfil&\ ---\
  2569. \vtop{\hsize=0.75\hsize\noindent\hang \strut#\strut}\hfil\cr
  2570. \noalign{\medskip\leftline{\hl{Unary operators}:}\smallskip}
  2571. defined&^^:\>{defined}: `\.{defined}'  is a unary operator that acts on
  2572. identifier tokens. 
  2573. `\.{defined id}' or equivalently `\.{defined(id)}' evaluates to~1 (true) if
  2574. the identifier is defined as a \WEB\ macro; 
  2575. to~0 (false) otherwise.  The construction `\.{\If{ }defined A}' works the
  2576. same way as
  2577. \.{\Ifdef{ }A}, but you can use `\.{defined}' in expressions, as in
  2578. \hbox{\.{\If{ }defined(A) || defined(B)}}.
  2579. (The parentheses around the macro names are optional.)
  2580. With the advent of `\.{defined}', the
  2581. \WEB\ preprocessor statements \Ifdef\ and \Ifndef\ become redundant, but
  2582. are often useful shorthands.\cr
  2583. -&Unary minus.\cr
  2584. !&^^:\>{"!}: Logical \hbox{\.{NOT}}. \.{!\expr} evaluates to~0 if \.{\expr}
  2585. is nonzero, and evaluates to~1 if \.{\expr} is~0.\cr
  2586. \TL&^^:\>\TL: One's complement of an integer. For example, $\.{\TL0} =
  2587. -1$.\cr 
  2588. \noalign{\medskip\leftline{\hl{Binary operators}:}\smallskip}
  2589. \^\^&^^:\>{\^\^}: Exponentiation (all languages). $2\hbox{\.{\^\^}}3 = 8$.\cr
  2590. \^\<**&^^:\>\^:^^:\>{**}: Exponentiation (\Fortran\ or \Ratfor).\cr
  2591. *\</\<\%&^^:\>\PC: Multiplication, division, and modulus: 
  2592. \.{$a$ \% $b$} means $a \mod b$; for example, \.{5 \% 3 = 2}. \cr
  2593. +\<-&The usual plus and minus.\cr
  2594. <<&^^:\>{<<}: \.{$a$ << $b$} means shift integer~$a$ left $b$~bits. $1 \ll
  2595. 3 = 8$.\cr
  2596. >>&^^:\>{>>}:  As above, but right-shift. $7 \gg 2 = 1$.\cr
  2597. <\<<=\<>\<>=&Evaluates to~1 if the inequality holds, to~0 otherwise.
  2598. E.g., \.{(2.0 < 3.0)} evaluates to~1.\cr
  2599. ==\<!=&^^:\>{==}: \.{$a$==$b$} (\.{$a$!=$b$}) evaluates to~1 (0) if $a$
  2600. equals~$b$; evaluates to~0 (1) otherwise.\cr 
  2601. \amp&^^:\>\amp: Bitwise \hbox{\.{AND}}. The truth table is \.{0b1100 \amp{
  2602. }0b1010 = 0b1000}.\cr 
  2603. \^&^^:\>\^: Bitwise \.{EXCLUSIVE OR} (C). (For \Fortran, use `\.{.xor.}'.)
  2604. The truth 
  2605. table is {\.{0b1100}~\.{.xor.}~\.{0b1010 = 0b0110}}.\cr
  2606. |&^^:\>{"|}: Bitwise~\hbox{\.{OR}}. The truth table is \.{0b1100 | 0b1010 =
  2607. 0b1110}.\cr 
  2608. \amp\amp&^^:\>{\amp\amp}: Logical~\hbox{\.{AND}}.\ \.{$a$ \amp\amp{ }$b$}
  2609. evaluates to~1 if both~$a$ and~$b$ are true (nonzero).\cr 
  2610. ||& Logical~\.{OR}. \.{$a$ || $b$} evaluates to~1 if either~$a$ or~$b$
  2611. are true.\cr 
  2612.   }}$$
  2613. Note in particular the use of the single caret, which is
  2614. language-dependent:  it is an 
  2615. exponentiation operator for \Fortran\ (just as in \TeX), but the
  2616. \.{EXCLUSIVE OR} operator for~\C. Also, note that the bitwise operators
  2617. should almost never be used. For 
  2618. logic, almost always you will be using~\.{==}, \.{!=}, \.{\&\&},
  2619. and~\.{||}. 
  2620. The preprocessor commands are ``active'' only for \FTANGLE. \FWEAVE\ will
  2621. format them in a reasonable way, but you can't, for example, comment out
  2622. some active \WEAVE\ operation such as~\atcmd{f} with `\If\dots\Endif'.
  2623. Furthermore, you can't use preprocessor commands to comment out the
  2624. \atcmd{i}~include statement. (Include statements are processed by the input
  2625. driver, so the \atcmd{i}~command never gets to the innards of the \WEB\
  2626. processors.  A single \atcmd{i}~command can be commented out with~\atcmd{\%},
  2627. since \atcmd{\%}~is also processed by the input driver.)
  2628. Here are some suggested uses for the preprocessing facility. To comment out
  2629. code, say
  2630. ^^<language!preprocessing>
  2631. {\codemode
  2632. \If(0) // You can also say ``\If\ 0''.
  2633. \Tab code // This text will not appear in the tangled output.
  2634. \Endif
  2635. \noindent To conditionally define a macro, say something like
  2636. ^^<macro!conditionally defining>
  2637. {\codemode
  2638. @m CRAY // You might define this macro from the command line.
  2639. \Ifdef\ CRAY
  2640. \Tab @m CRAY 1
  2641. \Tab @m VAX 0
  2642. \Else
  2643. \Tab @m CRAY 0
  2644. \Tab @m VAX 1
  2645. \Endif\ // |defined CRAY|
  2646. \If\ CRAY
  2647. \Tab @m INIT cray\_code
  2648. \Else
  2649. \Tab @m INIT vax\_code
  2650. \Endif\ // |CRAY|
  2651. \noindent To conditionally select a block of code, say something like
  2652. ^^<code!conditionally selecting>
  2653. {\codemode
  2654. \Tab program main
  2655. \Ifdef\ CRAY
  2656. \Tab @<Cray stuff@>
  2657. \Else
  2658. \Tab @<Vax stuff@>
  2659. \Endif\ // |defined CRAY|
  2660. \Tab end
  2661. ^^)preprocessor!\FWEB) ^^)preprocessing)
  2662. \dsubsection Built-in macro functions.[7.7.19] ^^(macro!built-in(
  2663. ^^(built-in!macros( 
  2664. \parinserto{2}{4}{0.5}
  2665. ``{\ssbf FWEB} contains a small number of built-in functions.''
  2666. In certain circumstances a macro function is desired that cannot be
  2667. accomplished by a user definition, or is so ubiquitous that it seems useful
  2668. to save the user the trouble of defining it himself. Therefore, for
  2669. enhanced flexibility, \FWEB\ contains a small number of \It{built-in}
  2670. functions.  Each of these functions begins with an underscore and is fully
  2671. in upper case.  These functions behave just like \WEB\ macros.  Therefore,
  2672. \It{do not define any macros of your own that begin with underscores,} even
  2673. if they don't correspond to the name of a built-in function.  This restriction
  2674. is intended to prevent conflict with certain auxiliary macros used
  2675. internally by \WEB\ in the course of expanding its built-ins.  
  2676. The following list describes the built-in functions in a (somewhat) logical
  2677. order.  They are summarized alphabetically in Appendix~L.
  2678. \dsubsubsection {\tt \_EVAL}.
  2679. The built-in function \.{\_EVAL} ^^:\>{\UL EVAL}:
  2680. evaluates its argument using the preprocessor
  2681. expression evaluator described above. (If an error is encountered during
  2682. the evaluation, a message is printed and the argument is returned without
  2683. any evaluation.) For example,
  2684. ^^<\>{\UL EVAL}>
  2685. {\codemode
  2686. @m A 2
  2687. @m B 3
  2688. _EVAL(defined A \amp\amp\ defined(B)) // `1'
  2689. _EVAL(A + 5.0*B) // `17.0' (Note the promotion to floating point.)
  2690. _EVAL(A==B) // `0'
  2691. _EVAL(A==1 || A==2) // `1'
  2692. _EVAL(x) // `x'
  2693. array[_EVAL(B+1)] // `array[4]'
  2694. \noindent The last example above shows a common usage of \.{\_EVAL},
  2695. namely in providing more readable tangled code. That is, although many
  2696. C~compilers accept the construction \.{array[3+1]}, in some circumstances
  2697. it may be more meaningful to see \.{array[4]} while you're debugging.
  2698. \dsubsubsection {\tt \_DEFINE, \_M, \_IFDEF, \_IFNDEF, \_UNDEF}.
  2699. A built-in form of deferred macro definition is achieved via \.{\_DEFINE}
  2700. or~\.{\_M}.
  2701. ^^:\>{\UL DEFINE}: ^^:\>{\UL M}:
  2702. These two names are synonyms; they are used by enclosing in parentheses all
  2703. the text that would normally follow an~\atcmd{m}, such as
  2704. {\codemode
  2705. _M(N\SP 5) // Equivalent to `@m N 5'.
  2706. _M(X(a,b) ((a)-(b)))
  2707. \noindent A subtlety occurs with a definition of the form 
  2708. ``\.{\_M(foo\ (bar))}''.  Because spaces are removed early in the
  2709. tokenization process, this definition is equivalent to ``\.{@m foo(bar)}''
  2710. (a one-argument macro with null replacement text) instead of what one
  2711. probably intended, ``\.{@m foo\ (bar)}'' (a zero-argument macro).  To get
  2712. the latter effect, say ``\.{\_M(foo=(bar))}''.
  2713. The companion macros \.{\_IFDEF}, \.{\_IFNDEF}, and \.{\_UNDEF}
  2714. are also provided.
  2715. ^^:\>{\UL IFDEF}: ^^:\>{\UL IFNDEF}: ^^:\>{\UL UNDEF}:
  2716. The syntax of the first two is, e.g,
  2717. \.{\_IFDEF(id,\truetext,\falsetext)}.  
  2718. Remember, these are macros, so their arguments must be enclosed in
  2719. parentheses---e.g., \.{\_UNDEF(X)}.
  2720. \dsubsubsection {\tt \_DO}.
  2721. A powerful means of \It{repetitively} defining a macro is provided
  2722. by~\.{\_DO}. ^^:\>{\UL DO}:
  2723. The syntax is 
  2724. {\codemode
  2725. _DO(I,Imin,Imax\It{[},dI\It{]})
  2726. \It{text}
  2727. \noindent This command is \FWEB's version of the \Fortran\ \&{do}~loop. It
  2728. behaves as though one said ``\&{do} $I=Imin,Imax\It{[},dI\It{]}$
  2729. \.\{\It{text}\.\}'', where the equals sign means a macro definition.  The
  2730. loop index should not be used as a \WEB\ macro for any other purposes,
  2731. since its previous definition will be destroyed.
  2732. (For symmetry, there ought to be a {\tt \_FOR} statement, but that's not in
  2733. place yet.)
  2734. \dsubsubsection {\tt \_INCR, \_DECR}.
  2735. The macros \.{\_INCR} and \.{\_DECR}
  2736. ^^:\>{\UL INCR}: ^^:\>{\UL DECR}:
  2737. increment or decrement by~1 a macro that expands to a number. For example,
  2738. if the \WEB\ macro~\.{N} expands to~\.5, then \.{\_INCR(N)} redefines~\.N
  2739. to be~\.6. These are included for convenience; they are defined in terms of
  2740. \.{\_M} and \.{\_EVAL}.
  2741. \dsubsubsection {\tt \_IF}.
  2742. The conditional \.{\_IF(expr,\truetext,\falsetext)} ^^:\>{\UL IF}:
  2743. expands to
  2744. \.{\truetext} if \.{expr} is true, or to \.{\falsetext} otherwise. \It{Note
  2745. that in almost all situations the preprocessor commands
  2746. \.{\If}\dots\.{\Else}\dots\.{\Endif} provide a better, more readable
  2747. alternative to \.{\_IF}; use this built-in only as a last resort.} One case
  2748. in which you must use \.{\_IF} is when \.{expr} contains a deferred macro.
  2749. \dsubsubsection {\tt \_ABS, \_MAX, \_MIN}.
  2750. A few other constructions built out of \.{\_IF} have been included for
  2751. convenience: \.{\_ABS(a)}, \.{\_MAX(a,b)}, and \.{\_MIN(a,b)}.
  2752. ^^:\>{\UL ABS}: ^^:\>{\UL MAX}: ^^:\>{\UL MIN}:
  2753. \dsubsubsection {\tt \_IFCASE}.
  2754. The \.{\_IFCASE} macro 
  2755. ^^:\>{\UL IFCASE}:
  2756. provides conditional evaluation based on the value
  2757. of a control integer. It is analogous to \TeX's \.{\\ifcase} macro or to
  2758. \Fortran's computed \&{goto}. The format is
  2759. {\codemode
  2760. _IFCASE(m,case_0,case_1,\dots,case_n,default)
  2761. \noindent Here $m$~is an
  2762. expression that evaluates to an integer in the range $0 \le m \le n$, and
  2763. the macro expands into the text \.{case\_m}. If $m$~is not in the above
  2764. range, then the default text is returned. (This is an example of a macro
  2765. that uses a variable number of arguments.)
  2766. \dsubsubsection {\tt \_IFELSE}.
  2767. The \.{m4}-like conditional
  2768. \.{\_IFELSE(macro1,macro2,\truetext,\falsetext)} ^^:\>{\UL IFELSE}:
  2769. expands each of \.{macro1} and \.{macro2}, then does a character-by-character
  2770. comparison. If the results are identical, \.{\truetext} is returned,
  2771. otherwise, \.{\falsetext} is returned. \It{Whenever possible use
  2772. \.{\If} instead.} Again, if \.{macro1} or \.{macro2} involve a deferred
  2773. macro, you must use \.{\_IFELSE}.
  2774. \dsubsubsection {\tt \_LEN}.
  2775. The macro \.{\_LEN(s)} ^^:\>{\UL LEN}:
  2776. interprets its argument as a character string
  2777. (without expanding it if it is a macro) and returns the length of that
  2778. string. For example, if you say
  2779. `\atcmd{m N 56}', then \.{\_LEN(N) -> 1}. Note that the string does not need to
  2780. be in quotes; that's done for you.  As a more complicated example, here's
  2781. one way to create a self-counted Hollerith string:
  2782. {\codemode
  2783. @m HOL(s) _LEN(#!s)##H###!s // HOL(abc) -> `3Habc'
  2784. \noindent Note that we had to be alert for the possibility that the
  2785. argument to \\{HOL} might inadvertently be a macro name, so we prevented
  2786. expansion with the \.{\#!}~operator.
  2787. \dsubsubsection {\tt \_POW}.
  2788. The exponentation macro \.{\_POW(x,y)}, ^^:\>{\UL POW}:
  2789. which expands~$x$ and~$y$ and returns~$x^y$,
  2790. is included for convenience; it is equivalent to \.{\_EVAL((x)\^\^(y))}.
  2791. \dsubsubsection {\tt \_TRANSLIT}.
  2792. The macro \.{\_TRANSLIT(s,from,to)} ^^:\>{\UL TRANSLIT}:
  2793. interprets each of its arguments as
  2794. strings (without expanding anything). Then $s$~is modified by replacing any
  2795. of the characters found in \\{from} by the corresponding characters
  2796. in~\\{to}. If \\{to} is shorter than \\{from}, then the excess characters in
  2797. \\{from}  are
  2798. deleted from~\\{s}. As a limiting case, if \\{to}~is empty, then all the
  2799. characters in \\{from} are deleted from~\\{s}. For example,
  2800. \.{\_TRANSLIT({\it s},aeiou,12345)} replaces the vowels in~\\{s} by the
  2801. corresponding digits, and \.{\_TRANSLIT(s,aeiou,)} deletes all the vowels.
  2802. The backslash may be used to escape a character, as in ANSI~C.  For
  2803. example,
  2804. \.{\_TRANSLIT("a\\"\\\\d","d\\\\a\\"","D,A'")} translates into~` \.{A',D}'.
  2805. Here we had to explicitly enclose strings involving '\.{\\"}' in double
  2806. quotes in order to avoid a complaint about an unterminated string.
  2807. \dsubsubsection {\tt \_A}.
  2808. The macro~\.{\_A} ^^:\>{\UL A}:
  2809. is the built-in equivalent of the~\.{@'} or~\.{@"} command.  
  2810. ^^{\>{@'}} ^^{\>{@""}}
  2811. The construction~\.{\_A('x')} functions essentially the same as
  2812. the command~``\.{@'x'}'', and ``\.{\_A("xyz")}'' is essentially the same
  2813. as~\.{@"xyz"}.  (We say ``essentially'' because the \.{@'} and~\.{@"}
  2814. commands are expanded on input, whereas the built-in function~\.{\_A} is
  2815. expanded on output.)  The need for such a built-in is evident from the
  2816. following example, in which the quantity to be converted to ASCII is
  2817. constructed via macro expansion:
  2818. ^^<\>{\PM'}>
  2819. {\codemode
  2820. @m OCTAL(n) OCTAL0(\\@&n)
  2821. @m OCTAL0(n) _A(#'n) // \.{OCTAL(123)} -> _A('\\123') -> 0123.
  2822. \noindent
  2823. Here one couldn't say something like ``\.{@m OCTAL(n) @'n'}'' for two
  2824. reasons:  first, \.{@}~commands are expanded on input; second, the
  2825. $n$~parameter wouldn't be expanded because it's inside a quoted string.
  2826. (Do you understand the function of the \.{@\&}~command in the definition of
  2827. \\{OCTAL}?)
  2828. \dsubsubsection {\tt \_STRING}.
  2829. The macro \.{\_STRING(macro)} ^^:\>{\UL STRING}: expands its argument, then
  2830. makes a string out of it (using the \.{\#*}~operator).
  2831. ^^{\>{\PM*}}
  2832. That is, it provides
  2833. one extra level of expansion over the basic stringize operation.  Compare,
  2834. for example, the following expansions:
  2835. {\codemode
  2836. @m A 1
  2837. @m S(s) #s
  2838. S(A) // `"A"'
  2839. _STRING(A) // `"1"'
  2840. \noindent This macro is included for convenience, as the user can define it
  2841. himself. 
  2842. \dsubsubsection {\tt \_UNQUOTE}, {\tt \_P}.
  2843. For certain special effects, one has the \.{\_UNQUOTE} built-in function
  2844. (formerly called ``\.{\_VERBATIM}''). ^^:\>{\UL UNQUOTE}: ^^{\>{\UL VERBATIM}}
  2845. If one says
  2846. ``\.{\_UNQUOTE("}\It{string}\.{")}'', the macro returns \It{string} without
  2847. the surrounding quotes. For example, this provides a way of getting the
  2848. special character~'\.\#' into the output from within a macro. For example,
  2849. the following macro creates C~preprocessor keywords:
  2850. {\codemode
  2851. @m PP(keyword) _UNQUOTE("#")##keyword
  2852. \noindent For the user's convenience, the macro~\.{\_P} ^^:\>{\UL P}:
  2853. is a synomym for
  2854. \.{\_UNQUOTE("\#")}. However, there is a subtlety here. Do you understand
  2855. why if one says
  2856. {\codemode
  2857. @m QQ(keyword) _P##keyword
  2858. \noindent one gets the following?
  2859. {\codemode
  2860. PP(define) // -> `#define'
  2861. QQ(define) // -> `_Pdefine'
  2862. \noindent To answer this question, carefully study the rules about macro
  2863. expansion and pasting. The proper way of defining~\\{QQ} is to
  2864. protect~\.{\_P} with left quotes:
  2865. {\codemode
  2866. @m QQ(keyword) `_P`##keyword
  2867. \dsubsubsection {\tt \_L}, {\tt \_U}.
  2868. Occasionally it is useful to change the case of a string parameter to a
  2869. macro.  This can be accomplished by means of the built-in functions~\.{\_L}
  2870. (change argument to lower case) and~\.{\_U} (change to upper case).  The
  2871. arguments to these functions must be quoted strings; they return the
  2872. case-converted string, also quoted.  For example, ``\.{\_L("ABC")}''
  2873. returns~``\.{"abc"}''. 
  2874. \parinsert{2}{4}{0.65}
  2875. The built-in functions `{\ssbf \_L}' and `{\ssbf \_U}' change the case of
  2876. their arguments.
  2877. An application in which such actions might be useful concerns mixed
  2878. programming in~C and \Fortran.  Suppose that in one's C~program the
  2879. \Fortran\ functions to be called had been distinguished by writing them in
  2880. upper case.  The code is supposed to be portable, and on at least one
  2881. machine the case-sensitive linker understands things just as they are.
  2882. However, suppose that on some other machine the \Fortran\ library was
  2883. compiled by a compiler that produced lower-case names---and, for good
  2884. measure, had appended an underscore to the name.  (This is precisely what
  2885. happens on Sun workstations.)  Here is how to macro up the situation to
  2886. make everyone happy:
  2887. {\codemode
  2888. @ In the \\WEB\\\ program \\Fortran\\\ functions will be in upper case, 
  2889. C functions will be in lower case.
  2890. @#if VAX
  2891. \Tab @m F(name) name
  2892. @#else
  2893. \Tab @m F(name) _UNQUOTE(_L(#name))##_ // Stringize, convert to l.c., 
  2894. \Tab\Tab\Tab\Tab remove quotes, append '_'.
  2895. @#endif
  2896. cfcn();
  2897. F(FORFCN)(); // Either |FORFCN()| or |forfcn_()|, depending on machine.
  2898. \dsubsubsection {\tt \_COMMENT}.
  2899. The macro \.{\_COMMENT(string)} ^^:\>{\UL COMMENT}:
  2900. generates a comment in the output file.
  2901. This is useful for macro definitions in which comments are desired; the
  2902. usual C-style comments are stripped off as the definition is being
  2903. absorbed. Thus, in~C, the definition 
  2904. \atcmd{m TEST a;\_COMMENT("Hello,\ world")b;} expands into 
  2905. `\.{a;/*\ Hello,\ world\ */b;}'. Note that the
  2906. \.{string} argument must be in quotes. (Actually, this is essential only
  2907. when the argument contains commas; otherwise, the commas will be
  2908. interpreted as argument delimiters and an error message about the wrong
  2909. number of arguments will ensue. However, it is good practice to always use
  2910. the quotes.) If you had wanted the comment to be on a separate line, you
  2911. could have inserted newlines into the string, as in
  2912. \.{"\\nHello,\ world\\n"}. In \Fortran, the comment is automatically put on
  2913. a separate line.
  2914. \dsubsubsection {\tt \_ASSERT}.
  2915. Error mechanisms are provided by several macros, \.{\_ASSERT} and
  2916. \.{\_ERROR}.  The \.{\_ASSERT(\expr)} ^^:\>{\UL ASSERT}:
  2917. macro evaluates \.{\expr}. If that expression is false, an error message is
  2918. sent (to both the terminal and the output file) and processing is aborted
  2919. immediately. This feature, motivated by ANSI~C, is intended to help one
  2920. verify certain conditions that must be true in order for processing to
  2921. proceed. For example, suppose you always intended to define the macros
  2922. \\{N1} and~\\{N2} from the command line. To make sure you didn't forget,
  2923. you could say at the beginning of your code
  2924. {\codemode
  2925. \_ASSERT(defined N1 && defined N2)
  2926. Like all of the built-ins, \.{\_ASSERT} is expanded on output, during
  2927. processing of the \It{code part}.  It will have no affect if it appears in
  2928. the definition part.
  2929. \dsubsubsection {\tt \_ERROR}.
  2930. The \.{\_ERROR(string)} ^^:\>{\UL ERROR}:
  2931. macro sends \.{string} to the standard error message
  2932. facility, but does not abort. Thus, \.{\_ERROR("That didn't work")}
  2933. generates an error message giving the line number and the file in which the
  2934. macro was expanded. Note that the \.{string} argument must be in quotes.
  2935. \dsubsubsection {\tt \_DUMPDEF}.
  2936. The \.{\_DUMPDEF} built-in is used for debugging \WEB\ macros. 
  2937. ^^:\>{\UL DUMPDEF}: 
  2938. It takes an arbitrary number of macro calls, separated by commas, as in
  2939. {\codemode
  2940. _DUMPDEF(A,B(1),C(x,y,z))
  2941. \noindent where it is assumed that~$A$, $B$, and~$C$ are macros with~0, 1,
  2942. and 3~arguments, respectively.  For each
  2943. macro, two lines are written to the terminal.  The first is a
  2944. representation of the original macro definition, the second is the
  2945. expansion.
  2946. \dsubsubsection {\tt \_LANGUAGE}, {\tt \_LANGUAGE\_NUM}.
  2947. The two built-in functions \.{\_LANGUAGE} and \.{\_LANGUAGE\_NUM}
  2948. ^^:\>{\UL LANGUAGE}: ^^:\>{\UL LANGUAGE\UL NUM}:
  2949. provide ways of endowing a \WEB\ macro with a language attribute.
  2950. The \.{\_LANGUAGE} macro expands into an \It{identifier}
  2951. (\It{not} a macro, unless you define it yourself) such as~`\.{\_C}'.  (See
  2952. the table below.)  It is
  2953. intended to be used in an  \.{\_IFELSE} statement.  The \.{\_LANGUAGE\_NUM}
  2954. macro expands into an integer (see the table below) and is intended to be
  2955. used as the first argument to an \.{\_IFCASE}.
  2956. \LANBUILTINS
  2957. For example, here is a way of defining a macro to be
  2958. the ``natural'' lower array index in either of~C or \Fortran, assuming that
  2959. one programs in only those two languages.
  2960. {\codemode
  2961. @m LOWER _IFELSE(_LANGUAGE,_C,0,1)
  2962. \noindent If you also sometimes use~\Cpp, however, you need a three-way
  2963. switch; the simplest way of achieving that is to use \.{\_LANGUAGE\_NUM}:
  2964. {\codemode
  2965. @m LOWER _IFCASE(_LANGUAGE_NUM,0,0,1)
  2966. \noindent This macro still isn't ideal, however.  It returns an explicit
  2967. value for the languages~C, \Cpp, and \Fortran--77, but would return nothing
  2968. for any other language.  If you started to use \Fortran--90 someday, you'd
  2969. get into trouble, and this kind of error can be hard to track down.  It's
  2970. best to be very explicit:
  2971. {\codemode
  2972. @m LOWER _IFCASE(_LANGUAGE_NUM,0,0,1,1,1,1,0)
  2973. \ddsubsubsection {\tt \_STUB}.
  2974. If a reference to an undefined module is encountered, it is replaced
  2975. automatically by a call to the built-in
  2976. \.{\_STUB}, with the module name as argument.  
  2977. ^^:\>{\UL STUB}:
  2978. The form of the call is
  2979. language-dependent.  Thus, if the module \.{@<Absent@>} is never defined,
  2980. then a reference to \.{@<Absent@>} will tangle to the
  2981. expansion of ``\.{\_STUB(Absent)}'', which in~C is by default
  2982. ``\.{\{missing\_mod("Absent");\}}''.  In \Fortran, the same reference would
  2983. tangle to ``\.{call nomod('Absent')}''.  If you don't like the default
  2984. actions, you can redefine \.{\_STUB} yourself with~\.{@m}.  The purpose of
  2985. this macro is to help one compile and debug a code that is not fully
  2986. developed. 
  2987. \dsubsubsection {\tt \_GETENV}, {\tt \_HOME}.
  2988. The built-in \.{\_GETENV(}\\{ENV}\.{)} ^^:\>{\UL GETENV}: ^^:\>{\UL HOME}:
  2989.  returns the value of the environment variable~\\{ENV}, 
  2990. ^^{variable!environment}
  2991. using the C~library call \\{getenv}.  The built-in
  2992. \.{\_HOME} is equivalent to \.{\_GETENV(HOME)}.
  2993. \dsubsubsection {\tt \_VERSION}.
  2994. The built-in \.{\_VERSION} ^^:\>{\UL VERSION}:
  2995. expands into a string containing the \WEB\ version number, such as~\.{"1.13"}.
  2996. \dsubsubsection {\tt \_MODULE\_NAME, \_SECTION\_NUM}.
  2997. ^^:\>{\UL MODULE\UL NAME}: ^^:\>{\UL SECTION\_NUM}:
  2998. Two built-ins provide information about where one presently in the web.
  2999. \.{\_MODULE\_NAME} expands to the name of the current module that is being
  3000. expanded; \.{\_SECTION\_NUM} is the number of the current section.
  3001. \dsubsubsection {\tt \_MODULES, \_SECTIONS}.
  3002. ^^:\>{\UL MODULES}: ^^:\>{\UL SECTIONS}:
  3003. Two built-ins provide some statistics about the structure of the program
  3004. being tangled or woven. \.{\_MODULES} expands into an integer that is the
  3005. total number of \It{independent} module names, plus~1 for the unnamed module.
  3006. \.{\_SECTIONS} expands into the maximum section number, as \WEAVE\ would
  3007. compute it. These numbers could be used as array bounds for various
  3008. esoteric purposes. For an example of the use of these macros, see the demo
  3009. program \.{breakpt.web}.
  3010. \dsubsubsection {\tt \_DATE, \_DAY, \_TIME}.
  3011. Finally, there are various date and time macros that expand into strings
  3012. containing the relevant information: \.{\_DATE}, \.{\_DAY}, and \.{\_TIME}.
  3013. ^^:\>{\UL DATE}: ^^:\>{\UL DAY}: ^^:\>{\UL TIME}:
  3014. These macros are intended primarily for internal use; they are used in
  3015. generating the comments output at the beginning of the tangled output and
  3016. at the end of the woven output.  However, they are available to the user as
  3017. well. These macros expand as follows:
  3018. $$\vbox{\halign{\.{#}\hfil&\ $\to$\ \.{"#"}\hfil\cr
  3019. \_DATE&August 15, 1989\cr
  3020. \_DAY&Monday\cr
  3021. \_TIME&23:59\cr}}
  3022. The built-in functions are summarized alphabetically in Appendix~L.
  3023. ^^)built-in!macros) ^^)macro!built-in)
  3024. \dsection OVERLOADING OPERATORS and IDENTIFIERS.[8.2]
  3025. For special effects in the woven output, there are special commands to help
  3026. one change the appearance of operators and identifiers.
  3027. \dsubsection OVERLOADING OPERATORS. ^^(operators!overloading(
  3028. \parinserto{2}{5}{0.45}
  3029. One can change the printed appearance of an operator with the `{\ssbf @v}'
  3030. command. 
  3031. A feature common to both~\Cpp\ and \Fortran--90 is \It{operator overloading},
  3032. the ability to extend or redefine the definition of an operator such as
  3033. `\.{.FALSE.}'
  3034. or~'\.='.  \Fortran--90 even allows one to define new ``dot''
  3035. operators---for example, one might define the operator ``\.{.IN.}'' to test
  3036. for inclusion in a set.  In a nontrivial extension of the original design,
  3037. \FWEAVE\ allows one to define how overloaded
  3038. operators should appear on output---for example, it is much more readable
  3039. to read ``$\&{if}\.(x \in \\{set}\.)$'' than ``\&{if}\.(x\ \.{.IN.}\
  3040. \\{set}\.)''.  Indeed, this feature can be used even when the language
  3041. does not permit overloading in order to customize the appearance of the
  3042. woven output.
  3043. The \atcmd{v}~control code is used to change the appearance of an operator.
  3044. ^^{operator!changing appearance of}
  3045. The format is
  3046. {\codemode
  3047. @v \It{new}_\It{operator}_\It{symbol}_\It{or}_\It{name} "\It{\TeX\ material}" \It{old}_\It{operator}
  3048. \noindent This means ``Display the new operator according to the \It{\TeX\
  3049. material}, but treat it like the old operator---e.g., unary or binary---for
  3050. formatting purposes.  The 
  3051. quoted \TeX\ material is treated just like a C~string, so for example if
  3052. you want to include a backslash you must escape it with another backslash.
  3053. For example, we can make an equals sign display on output as
  3054. a large left arrow by saying
  3055. {\codemode
  3056. @v = "\\\\Leftarrow" =
  3057. \noindent Then, if you say ``\.{x = y;}'', it will display as ``$x
  3058. \Leftarrow y;$''.  Two \Fortran\ examples are
  3059. {\codemode
  3060. @v .FALSE. "\.{.FALSE.}" .FALSE.
  3061. @v .IN. "\\in" +
  3062. \noindent which makes the operator \.{.FALSE.} display as ``\.{.FALSE.}''
  3063. instead of the default~${\cal F}$ (but still behave in the default
  3064. way---i.e., like an ordinary expression), 
  3065. and makes the operator~\.{.IN.} display as~``$\in$'' (and behave like a
  3066. binary operator).
  3067. This feature can go a long way toward enhancing readability of the woven
  3068. output, particularly when operators are actually being overloaded.  It can
  3069. also lead to arbitrarily bizarre output that no-one else will understand.
  3070. As usual, restraint is advised.
  3071. Examples of operator overloading can be found in the sample~\Cpp\ and
  3072. \Fortran--90 code in Appendix~E.
  3073. ^^)operators!overloading)
  3074. \vfill\eject
  3075. \dsubsection OVERLOADING IDENTIFIERS. ^^(identifiers!overloading(
  3076. \parinserto{1}{5}{0.45}
  3077. One can change the printed appearance of an identifier with the `{\ssbf @W}'
  3078. command. 
  3079. Although operator overloading is quite useful, it does not allow one to
  3080. change the appearance of identifiers.  In its most general form, such a
  3081. facility becomes quite complicated; one must endow \FWEAVE\ with a
  3082. macro-processing facility analogous to that of \FTANGLE.  This has not been
  3083. done yet (probably it will be someday).  In the meantime, one has the
  3084. command~`\.{@W}, ^^:\>{@W}:
  3085. which provides a restricted form of such a facility.  \It{This command, new
  3086. with version~1.30, is
  3087. experimental, and not firmly established.  Changes in usage and/or syntax
  3088. may be made in future versions.}
  3089. The most general form of the `\.{@W}~command is
  3090. {\codemode
  3091. @W \It{identifier} "\It{replacement text}"
  3092. \noindent This means:  Replace any references to \It{identifier} in the
  3093. woven output with the \It{replacement text}.  
  3094. A more restrictive form is
  3095. {\codemode
  3096. @W \It{identifier} \\newmacro
  3097. \noindent which replaces references to \It{identifier} with a call to
  3098. \.{\\newmacro}.  (Note that there are no quotes in this form.)
  3099. The shortest form is
  3100. {\codemode
  3101. @W \It{identifier} .
  3102. \noindent which replaces references to \It{identifier} with a call to
  3103. \.{\\identifier}.  For example, the identifier~\\{x} normally appears in
  3104. woven output as ``\.{\\Wshort\{x\}}''.  If one says
  3105. {\codemode
  3106. @W x .
  3107. \noindent one will instead get the macro reference~``\.{\\x}'', which could
  3108. be defined to give a variety of special effects.
  3109. It should now be clear how the previous ``\&{call} \\{integrate}'' example
  3110. was formatted.  One simply said
  3111. {\codemode
  3112. @W alpha .
  3113. @W beta .
  3114. @W fM "f_{\\\\rm M}"
  3115. \Tab call integrate(x,alpha,beta,fM)
  3116. One of the important uses of this facility is to expedite special
  3117. formatting of array references.  This subject is discussed separately below
  3118. in the section on ``Special array formatting,'' where an example is given.
  3119. ^^)identifiers!overloading)
  3120. \section RATFOR.[9.3] ^^(Ratfor:\RATFOR(
  3121. Closely related to macro preprocessing is the notion of \It{statement
  3122. translation}. ^^:statement!translation:
  3123. In statement translation, \FWEB\ recognizes a special keyword
  3124. or construction that is not part of the source language, and automatically
  3125. translates that construction into valid compilable code. It is a more
  3126. general operation than macro expansion, although it reduces to that in the
  3127. simplest cases.
  3128. \parinsert{2}{6}{0.6}
  3129. ``Ratfor provides modern control flow statements..., so [one] can do
  3130. structured programming properly.''
  3131. In the present version of \FWEB, statement translation is active only when
  3132. the language is \Ratfor.  The \Ratfor\ language was introduced by \KP\ in
  3133. {\sl Software Tools} as a tool for explaining good programming practice; it
  3134. is also a vastly superior way of writing understandable \Fortran\ code. In
  3135. their words, ``bare Fortran is a poor language indeed for programming or
  3136. for describing programs. So we have written all of our programs in a simple
  3137. extension of Fortran called `Ratfor' (short for Rational Fortran). \Ratfor\
  3138. provides modern control flow statements\dots, so we can do structured
  3139. programming properly. It is easy to read, write, and understand, and
  3140. readily translates into Fortran\dots\ or similar high-level languages.''
  3141. Unfortunately, extant \Ratfor\ processors essentially convert the new
  3142. statements into pre-\Fortran--77 code, with many
  3143. \&{goto}'s, so the resulting code can be somewhat messy and hard to read.
  3144. If your code worked perfectly the first time, this would not be
  3145. an issue since you would never have to see the \Fortran\ file. However, if
  3146. it is necessary to work with a debugger (and it very frequently is!), then
  3147. it is the generated \Fortran\ code at which one will be looking. It is
  3148. desirable to make that code as readable (and as efficient) as possible.
  3149. Thus, \FTANGLE\ has been taught the \Ratfor\ language and, by default, will
  3150. translate it directly to \Fortran\ code.  Translations into both
  3151. \Fortran--77 and \Fortran--90 are supported.
  3152. (Certain existing codes use a now-archaic mode of \FTANGLE\ in which
  3153. \Ratfor\ code was just \TANGLE d into a \.{RAT} file that was intended to
  3154. be passed through a separate \Ratfor\ processor. \It{This mode has died; it
  3155. should not be used for new codes.} To tell \FTANGLE\ to \It{not} translate
  3156. \Ratfor\ statements, you must use the command-line option `\.{-q}'.)
  3157. ^^:\>{-q}:
  3158. ^^[Ratfor:\RATFOR!syntax] ^^[syntax!Ratfor:\RATFOR]
  3159. The syntax of the \Ratfor\ language understood by \FWEB\ is as C-like as
  3160. possible.  It features the following:
  3161. {\narrower
  3162. \Item The syntax is totally free-form.
  3163. \Item ^^{Ratfor:\RATFOR!declarations} ^^{Ratfor:\RATFOR!statements}
  3164. Declarations and statements are ended by ^{semicolons}. (An auto-semi
  3165. mode can fill these in for you; see below.)  
  3166. \Item ^^{Ratfor:\RATFOR!program units}
  3167. Program units should be begun by either the \&{program}, \&{subroutine},
  3168. \&{function}, or \&{blockdata} statement. Use \&{program main} instead of an
  3169. unnamed main program; the latter may confuse \FWEAVE.
  3170. \Item The body of the subroutine is
  3171. delimited by ^{braces} (as are groups of statements that form the bodies of
  3172. keywords such as \&{else} or~\&{do}).
  3173. \Item ^^{Ratfor:\RATFOR!declaring functions in}
  3174. ^^[declarations!argument, in \RATFOR]
  3175. Functions are declared in the same way as the ``old'' style of
  3176. argument declaration in~C. (There is no concept of function prototyping.)
  3177. Thus, the outline of a \Ratfor\ function is
  3178. {\codemode
  3179. function f(x,y)
  3180. \Tab real x,y;
  3181. \item{} (Actually, as far as the \Fortran\ code that is generated is
  3182. concerned, it makes no difference whether the function arguments are
  3183. declared before or after the opening brace.  However, it is useful
  3184. logically and typographically to set them off as suggested.)
  3185. \Item ^^{statement!\<{end}} ^^{Ratfor:\RATFOR!\<{end} statement}
  3186. No \&{end} statement should be used; that is filled in automatically when
  3187. \FTANGLE\ processes the closing brace. 
  3188. \Item ^^{statement!\<{return}} ^^{Ratfor:\RATFOR!\<{return} statement}
  3189. Function values can be returned with a \&{return} statement of the form
  3190. `\.{return \expr;}'. 
  3191. \Item ^^{Ratfor:\RATFOR!statement labels}
  3192. Numeric statement labels, if used, should be followed by a colon.
  3193. \Item ^^{Ratfor:\RATFOR!comments}
  3194. Comments should be C-style: \hbox{`\.{/*\dots */}'} or \hbox{`\.{//\dots}'}. 
  3195. ^^:comment!Ratfor\actual\RATFOR: 
  3196. \Item When one is inside a recognizable \&{program}, \&{subroutine}, 
  3197. \&{function}, or \&{blockdata} unit, the built-in function \\{\_ROUTINE}
  3198. ^^{\>{\UL ROUTINE}} 
  3199. expands to the name of the program unit.  (This is true only for \Ratfor;
  3200. \FTANGLE\ is not so intelligent in the other languages.)
  3201. \Item ^^{\>{++}} ^^{\>{--}} ^^{\>{+=}} ^^{\>{-=}} ^^{\>{*=}} ^^{\>{/=}}
  3202. ^^{operator!post-increment} ^^{operator!compound assignment}
  3203. The special operators~`\.{++}', `\.{--}', `\.{+=}',`\.{-=}', `\.{*=}',
  3204. and~`\.{/=}' are allowed in restricted places; see the discussion in the
  3205. section ``Additional features.''  
  3206. \Item ^^{Ratfor:\RATFOR!character strings}
  3207. \Ratfor\ character strings must be
  3208. enclosed in double, not single, quotes (consistent with~C, but unlike
  3209. \Fortran--77).
  3210. ^^{character!strings}
  3211. As in~C, single characters enclosed
  3212. by single quotes are interpreted as character constants ^^{character!constants}
  3213. and are translated
  3214. into the ASCII integer equivalent; ^^{ASCII!integer equivalent of}
  3215. for example, $\.{'a'} \to \.{97}$.
  3216. Thus, an example of a \Ratfor\ function
  3217. is as follows:
  3218. {\codemode
  3219. @m ERROR call error(_ROUTINE)
  3220. real function f(x)
  3221. \Tab real x; // We should have $x \\ge 0$.
  3222. real y;
  3223. if(x >= 0) y = sqrt(x);
  3224. \Tab \{
  3225. \Tab ERROR;
  3226. \Tab y = 0.0;
  3227. \Tab \}
  3228. return y;
  3229. \Ratfor\ statements can be easily ``stacked''.
  3230. For example, the following is valid \Ratfor:
  3231. \vbox{
  3232. {\codemode
  3233. if(do_it)
  3234. \Tab for(i=1; i<100; i *= 2)
  3235. \Tab\Tab while(k < i)
  3236. \Tab\Tab\Tab do j=0,k;
  3237. \Tab\Tab\Tab\Tab a(i,j,k) = 1.0;
  3238. \noindent Note the simplicity of the construction: no \&{end} statements
  3239. are required to terminate the loops.
  3240. An important notion in the C~language whose essence is retained in
  3241. \Ratfor\ is the \It{compound statement}. ^^:statement!compound:
  3242. Here, a compound statement is any group of
  3243. statements delimited by braces. Compound statements may be used wherever a
  3244. simple statement may be. Thus, in the above example any or all of the last
  3245. four lines could be replaced by a compound statement---for example,
  3246. {\codemode
  3247. if(do_it)
  3248. \Tab \{
  3249. \Tab x = dx;
  3250. \Tab for(...)
  3251. \Tab\Tab while(...)
  3252. \Tab\Tab\Tab do ...
  3253. \Tab\Tab\Tab\Tab \{
  3254. \Tab\Tab\Tab\Tab a...;
  3255. \Tab\Tab\Tab\Tab b...;
  3256. \Tab\Tab\Tab\Tab \}
  3257. \Tab x *= alpha;
  3258. \Tab \} // |do_it|
  3259. \noindent Here, as in~C, the use of braces creates a quite concise and
  3260. readable code. 
  3261. ^^[braces]
  3262. \parinsert{2}{7}{0.6}
  3263. ``It is
  3264. truly remarkable how much heated debate can result from such trivial
  3265. questions as whether braces are better than {\ssbf begin} and {\ssbf
  3266. end}...'' 
  3267. [Some people disagree. Indeed, again quoting \KP, ``It is
  3268. truly remarkable how much heated debate can result from such trivial
  3269. questions as whether braces are better than \&{begin} and \&{end}\dots''
  3270. In this regard, it is very important to observe that in many situations neither
  3271. braces nor keywords are required to terminate loops; loops whose bodies are
  3272. simple statements terminate automatically, just as in~C.
  3273. The principle argument that appears to be raised against braces is that if
  3274. they enclose long blocks of code they can get lost or misplaced. However,
  3275. note that at the user's discretion braces can be labelled (the previous
  3276. example shows one possible style); furthermore,
  3277. such long blocks are strongly discouraged by the philosophy and design of
  3278. \WEB. As you know by now, the proper use of named modules leads to a
  3279. programming style in which no modules need be longer than, ideally, about a
  3280. dozen lines. For modules that short, it's very difficult to lose braces;
  3281. rather, the braces tend to enhance the logical structure and we believe
  3282. that they are more pleasing to, and more readily captured by, the eye than
  3283. verbose keywords. In any event, our design goal of syntactical consistency
  3284. with~C is obviously better achieved by using braces rather than keywords.
  3285. Therefore, within the framework of the present philosophy, keywords such as
  3286. \&{end do} or \&{end while} seem to represent a definite step backwords and
  3287. are not used.]
  3288. \subsection Ratfor--77 commands.[9.1.7]
  3289. ^^(keywords!Ratfor:\RATFOR(
  3290. Here are the \Ratfor\ constructions recognized and expanded by \TANGLE. In
  3291. the following, the construction \.{\stmt} stands 
  3292. for either an arbitrary number of statements enclosed by braces (a compound
  3293. statement), or a simple statement terminated by a semicolon. (Recall that the
  3294. \Ratfor\ syntax is free-form, so the newlines and spacings in the examples are
  3295. inserted entirely for readability.)
  3296. \subsubsection {\bf if}.
  3297. The \&{if} statement looks exactly like that of~C (the \&{else} clauses are
  3298. optional): 
  3299. ^^:\<{if}: ^^:\<{else}: ^^:\<{else if}:
  3300. {\codemode
  3301. if(\cond)
  3302. \Stmt
  3303. else if(\It{another condition})
  3304. \Stmt
  3305. \Stmt
  3306. \noindent There may be multiple \.{else if}'s.
  3307. Functionally, this statement is identical to
  3308. \Fortran's \&{if}\dots\&{then}\dots\&{else
  3309. if} \dots\&{then}\dots\&{else}\dots\&{end if}
  3310. construction (into which it is expanded), but the keywords have been
  3311. abolished. The simple 
  3312. \Fortran\ \&{if}, such as `\.{if(x < 0.0) x = 0.0;}',
  3313. is a special case of the general construction. For simplicity, \Ratfor\
  3314. also expands this into an `\&{if}...\&{then}...\&{endif}'.
  3315. \subsubsection {\bf while}.
  3316. The \&{while} statement is also equivalent to that of~C:
  3317. ^^:\<{while}:
  3318. {\codemode
  3319. while(\cond)
  3320. \Stmt
  3321. \noindent The condition is checked. If it is true, the body of the \&{while}
  3322. is executed. Then the process repeats.  If the condition is false, control
  3323. passes to the first statement after the body of the \&{while}. This means
  3324. that if the condition is false initially, the loop is not executed even
  3325. once.
  3326. \subsubsection {\bf for}.
  3327. The \&{for} statement is equivalent to that of~C. It is a souped-up version
  3328. of the \&{while} that includes initialization and reinitialization:
  3329. ^^:\<{for}:
  3330. {\codemode 
  3331. for(\It{initialization}; \It{condition}; \It{reinitialization}) 
  3332. \Stmt
  3333. \noindent The
  3334. initialization (which must be a \It{single} \Fortran\ statement;
  3335. C~programmers beware!)
  3336. is performed. The condition is tested. If it is false,
  3337. processing terminates. If is is true, then the body of the \&{for} is
  3338. executed. At the bottom of the loop, the reinitialization (which must also
  3339. be a \It{single} \Fortran\ statement) is performed;
  3340. then the condition is tested again and the processing iterates. For example,
  3341. {\codemode
  3342. for(i=0; i<10; i++) a(i) = i;
  3343. \noindent is equivalent to \Fortran--90's 
  3344. {\codemode
  3345. do i=0,9
  3346. \Tab a(i) = i
  3347. end do
  3348. \noindent However, it is important to note that for arbitrary bodies even
  3349. this simple \&{for} is \It{not} equivalent to the \Fortran~\&{do}, since
  3350. \Fortran\ does not allow one to tamper with the loop index within the loop
  3351. but there is no such restriction in \Ratfor\ or~C. Therefore, the
  3352. construction is translated into an \&{if} and a \&{goto}; no attempt is
  3353. made to optimize it into a \&{do}.  \Ratfor\ programmers working with
  3354. vectorizing compilers should employ \&{do}'s instead of simple \&{for}'s
  3355. for critical loops.
  3356. \subsubsection {\bf repeat---until}.
  3357. The \&{repeat}--\&{until} construction executes the body before the
  3358. condition is tested, so it is guaranteed to be executed at least once; it
  3359. corresponds to the \&{do}--\&{while} construction of~C: 
  3360. ^^:\<{repeat}:^^:\<{until}:
  3361. {\codemode
  3362. repeat
  3363. \Stmt
  3364. until(\cond);
  3365. \noindent Unlike the corresponding loop in~C,
  3366. the \&{until} clause is optional. If it is omitted, one gets an
  3367. infinite loop that must be broken out of by a \&{break} or \&{goto}.
  3368. That loop is equivalent to C's \.{while(1) \{...\}} or \Fortran--90's \.{do
  3369. \{...\}}. 
  3370. \subsubsection {\bf do}.
  3371. The \Ratfor~\&{do} statement is fundamentally \Fortran's:
  3372. ^^:\<{do}:
  3373. {\codemode
  3374. do \It{index}=\It{lower},\It{upper}[,\It{increment}]
  3375. \Stmt
  3376. \noindent or
  3377. {\codemode
  3378. do \It{index}=\It{lower},\It{upper}[,\It{increment}];
  3379. \Tab\It{simple statement};
  3380. \noindent Functionally, these are equivalent to
  3381. {\codemode
  3382. for(index=lower; index<=upper; index += increment)
  3383. \Stmt
  3384. \noindent but the \&{do} may be implemented more efficiently by the compiler.
  3385. Note the semicolon after \It{increment} in the second example. This is
  3386. annoying, as it looks 
  3387. different than the syntax for the \&{for} statement.  Unfortunately, the
  3388. standard \Fortran\ syntax is simply incompatible here with the uniform
  3389. \Ratfor\ syntax. (If a simple statement follows the
  3390. \&{do}, some terminator is required in order to separate the increment from
  3391. the beginning of the statement. The carriage return at the end of the
  3392. physical line cannot be used because the syntax is free-form.)  If you
  3393. would like to make things look more symmetric, you could define a \WEB\
  3394. macro:
  3395. {\codemode
  3396. @m DO(i,min,imax) do i=imin,imax;
  3397. or, more simply and also more generally,
  3398. {\codemode
  3399. @m DO(i,...) do i=#.;
  3400. \noindent [If you are using the auto-semi mode ^^{mode!auto-semi}
  3401. (see below), you should omit the semicolon; it will be inserted for you.]
  3402. Note that the \Ratfor\ syntax makes multiple \&{do} loops look very clean;
  3403. neither braces nor \&{end} keywords are required in the following example:
  3404. {\codemode
  3405. do i=1,10;
  3406. do j=1,10;
  3407. \Tab a(i,j) = 0.0;
  3408. \subsubsection {\bf break}, {\bf next}.
  3409. In the bodies of the above loops (\&{if}~statements are not loops), the special
  3410. commands \&{break} and \&{next} are allowed.  The \&{break} command
  3411. ^^:\<{break}: 
  3412. exits the loop immediately. The
  3413. \&{next} command ^^:\<{next}:
  3414. is functionally equivalent
  3415. to the \&{continue} statement of~C. Following \KP, ``\&{next} goes to the
  3416. \It{condition} part of a \&{while}, \&{do}, or \&{until}, to the top of an
  3417. infinite \&{repeat} loop, and to the \It{reinitialize} part of a \&{for}.''
  3418. (Note that other statement processors may implement this statement
  3419. differently.) 
  3420. Only one level of looping can be broken
  3421. out of by \&{break}. This restriction is deliberate, not fundamental. A
  3422. \.{break\ $n$} statement, though very feasible to code, is not
  3423. allowed partly because C~does not and partly (equivalently?) because it is
  3424. felt that its 
  3425. presence would make certain coding errors more likely. To conveniently
  3426. break out of several levels of looping, use \&{goto}; this is one of its
  3427. few legitimate uses\cite{Knuth}.
  3428. \subsubsection {\bf switch}.
  3429. Finally, we have the \&{switch} statement, again functionally equivalent
  3430. to that of~C: 
  3431. ^^:\<{switch}: ^^:\<{case}: ^^:\<{default}:
  3432. {\codemode
  3433. switch(\expr)
  3434. \Tab \{
  3435. \Tab case \It{integer\_expression}:
  3436. \Tab\Tab .
  3437. \Tab\Tab .
  3438. \Tab\Tab break; // Use this to prevent falling through to the next case.
  3439. \Tab .
  3440. // More case statements.
  3441. \Tab .
  3442. \Tab default:
  3443. \Tab\Tab .
  3444. \Tab\Tab .
  3445. \Tab\Tab break; // Optional here, but still a good idea.
  3446. \Tab \}
  3447. \noindent The \.{\expr} is evaluated at run time and converted to an
  3448. integer. If any of the listed cases correspond to that integer, control is
  3449. passed there. Otherwise, if the optional \&{default} statement is present,
  3450. control is passed there. (It is not necessary that the \&{default} be last
  3451. in the \&{switch}.) Otherwise, the entire \&{switch} body is skipped.
  3452. \parinsert{2}{4}{0.35}
  3453. Use {\ssbf break} to terminate a {\ssbf case}.
  3454. The arguments of the cases should be or expand to single integers. Lists of
  3455. cases, as in `\.{case 2-5:}', are not allowed. ^^{cases, list of}
  3456. If the cases are all pure
  3457. numbers or macros known at \TANGLE\ time, then in certain circumstances the
  3458. \Ratfor--77 \&{switch} will be implemented using a computed \&{goto}. This
  3459. will occur 
  3460. if the list of cases is sufficiently dense, with few gaps, or if the number
  3461. of cases is sufficiently large, provided the spread in the case values is
  3462. not too great.  Otherwise, in \Ratfor--77 the
  3463. \&{switch} is expanded into a series of \&{if} statements. In this case,
  3464. if the
  3465. \&{switch} is lengthy, it will pay to put the most frequently expected case
  3466. first.  In \Ratfor--90 the \&{switch} is translated into a ``\&{select case}''
  3467. construction. 
  3468. More precisely, the decision of whether to use a computed \&{goto} is based
  3469. on three parameters---$r$, $m$, and~$s$. Let the number of cases in the
  3470. \&{switch} be~$n$ and the spread of case values, plus~1, be~$\Dv$. The
  3471. computed \&{goto} is chosen if both $n > m$ and $\Dv < s$ or, failing that, if
  3472. $\Dv/n \le r$. By default, $m = 5$, $s = 128$, and $r = 2.0$.  If you
  3473. absolutely don't want the computed \&{goto} for some reason (maybe because
  3474. it doesn't vectorize), use $r = 0.0$.  These
  3475. parameters can be set by the user through the command-line option
  3476. ``\.{-rg}''.  ^^{\>{-rg}}
  3477. The format is, for example, ``\.{-rgm5s128r2.0}''. The \.m, \.s,
  3478. and~\.r keyletters may appear in any order, or may be absent. \It{(Now that the
  3479. style file exists, these parameters should really be defined there. That
  3480. will be done at some point.)}
  3481.         
  3482. In the \&{switch}, the \&{break} statements are optional. If they are
  3483. missing, control just continues to the next case. This is in accord with
  3484. C's behavior, but {\it is in disagreement with the original \Ratfor\ design}.
  3485. Note that a \&{next} statement appearing inside a \&{switch} has nothing to
  3486. do with that \&{switch}.  (The \&{switch} is not a loop.)  Rather, it is
  3487. related to whatever loop encloses the \&{switch}.
  3488. Here is an example of a \&{switch}. ^^<\<{switch}>
  3489. It assumes that the single
  3490. character~$c$ has been read. It should be either `\.y' or~`\.n', in either
  3491. upper or lower case. If it is~`\.y', the \\{execute} subroutine is called;
  3492. if it is~`\.n', 
  3493. nothing is done; if it is anything else, an error routine is called.
  3494. Note how the lower-case cases fall through to the upper-case ones, and how
  3495. the \&{break} statement is used to terminate the processing of a group of
  3496. cases. 
  3497. {\codemode
  3498. switch(ichar(c)) // Use intrinsic function to return integer value.
  3499. \Tab \{
  3500. \Tab case 'y':
  3501. \Tab case 'Y':
  3502. \Tab\Tab call execute;
  3503. \Tab\Tab break;
  3504. \Tab case 'n':
  3505. \Tab case 'N':
  3506. \Tab\Tab break;
  3507. \Tab default:
  3508. \Tab\Tab call error(c);
  3509. \Tab\Tab break;
  3510. \Tab \}
  3511. \dsubsection Ratfor--90 commands.[9.2.5]
  3512. In \Ratfor--90, additional constructions are supported.  In general, where
  3513. \Fortran--90 has a compound construction that ends with an \&{end}
  3514. statement, such as \&{type person}\dots\&{end type person}, \Ratfor\
  3515. abolishes the \&{end} statement and encloses the statements with braces.
  3516. It will expand the construction into valid \Fortran--90, including the
  3517. optional labelled form of the \&{end} statement, such as \&{end module}.
  3518. Furthermore, \Fortran--90 allows optional symbolic labels on such compound
  3519. constructions.  \Ratfor--90 permits these as well, as in
  3520. {\codemode
  3521. test: if(x)
  3522. \Stmt
  3523. \noindent This construction will be expanded into code that ends with
  3524. ``\&{end if test}''.  Such symbolic labels should \It{not} be declared with
  3525. the automatic statement numbering facility;  that is, do \It{not} say
  3526. `\atcmd{m test \#:0}'.
  3527. \subsubsection {\bf module}. ^^:\<{module}:
  3528. The \&{module} statement is analogous to the \&{class} statement of \Cpp:
  3529. {\codemode
  3530. module \It{module\_name}
  3531. \Stmt
  3532. \noindent As an example,
  3533. {\codemode
  3534. module work_arrays
  3535. \Tab \{
  3536. \Tab integer n;
  3537. \Tab real, allocatable, save :: A(:), B(:,:), C(:,:,:);
  3538. \Tab \}
  3539. \subsubsection {\bf type}. ^^:\<{type}:
  3540. The \&{type} statement is analogous to the \&{struct} statement of~C:
  3541. {\codemode
  3542. type \It{type\_name}
  3543. \Stmt;
  3544. \noindent As an example,
  3545. {\codemode
  3546. type line
  3547. \Tab \{
  3548. \Tab real, dimension(2,2) :: coord;   // $x_1$, $y_1$, $x_2$, $y_2$.
  3549. \Tab real                 :: width;   // Line width in centimeters.
  3550. \Tab integer              :: pattern; // 1 for solid, 2 for dash, 3 for dot.
  3551. \Tab \};
  3552. \noindent Note the terminating semicolon, which is consistent with the
  3553. \&{struct} statement of~C and~\Cpp.
  3554. \subsubsection {\bf interface}. ^^:\<{interface}:
  3555. The \&{interface} statement is \Fortran--90's way of overloading operators
  3556. or procedures.  The corresponding \Ratfor\ statement has one of the three
  3557. following forms: 
  3558. {\codemode
  3559. interface \It{procedure\_name}
  3560. \Stmt
  3561. interface operator(\It{operator})
  3562. \Stmt
  3563. interface assignment(\It{assignment operator})
  3564. \Stmt
  3565. \noindent As an example,
  3566. {\codemode
  3567. interface operator(*)
  3568. \Tab \{
  3569. \Tab function boolean_and(b1,b2)
  3570. \Tab\Tab \{
  3571. \Tab\Tab logical :: boolean_and(size(b1));
  3572. \Tab\Tab logical, intent(in) :: b1(:), b2(size(b1));
  3573. \Tab\Tab \}
  3574. \Tab \}
  3575. \subsubsection {\bf where}. ^^:\<{where}:
  3576. The \&{where} statement is supported (the \&{else} clause
  3577. is optional):
  3578. ^^:\<{where}: ^^:\<{else}:
  3579. {\codemode
  3580. where(\cond)
  3581. \Stmt
  3582. \Stmt
  3583. \subsubsection {\bf contains}, {\bf private}, {\bf sequence}.
  3584. ^^:\<{contains}: ^^:\<{private}: ^^:\<{sequence}:
  3585. The keywords \&{contains}, \&{private}, and \&{sequence} should be followed
  3586. by colons; for example,
  3587. {\codemode
  3588. subroutine outer
  3589. \Tab\{
  3590. \Tab ...
  3591.    contains:
  3592. \Tab subroutine inner(b)
  3593. \Tab\Tab\{...\}
  3594. \Tab\}
  3595. ^^)keywords!Ratfor:\RATFOR)
  3596. \dsubsection Additional features of \Ratfor.[9.3.4]
  3597. A few additional topics are useful to discuss.
  3598. \dsubsubsection \Ratfor's automatic comments.
  3599. ^^:comment!Ratfor\actual\RATFOR!automatic: 
  3600. As \FWEB\ translates \Ratfor\ statements, it typically writes comment lines
  3601. to the output file to help one correlate the source statement with the
  3602. translated output. (Look at some sample output for examples.)  If one
  3603. wishes to suppress such comments, he may use the command-line option
  3604. `\.{-k}'. ^^{\>{-k}}
  3605. See the detailed description under `Command-line options'.
  3606. \comment
  3607. We end the discussion of the \Ratfor\ commands with a simple example that
  3608. illustrates the basic \Ratfor\ syntax. (It does not illustrate most of the
  3609. commands; 
  3610. more complicated examples can be found in \KP.)  The goal is to sum the first
  3611. $n$~integers. This is done in a \Ratfor\ function called from a \Ratfor\
  3612. main program. The answer is printed out by a C~function, because I/O is so
  3613. much nicer in~C and furthermore the exercise can then illustrate the
  3614. ubiquitous considerations about passing arguments between mixed languages;
  3615. recall that \Fortran\ passes addresses while C~passes values.
  3616. {\codemode
  3617. @ Sum the first n integers.
  3618. @m SEE(n) see(n,sum(n))
  3619. program main
  3620. integer k;
  3621. do k=1,10;
  3622. \Tab SEE(k);
  3623. @<C@>@;
  3624. @ A Ratfor function that returns the sum of the first n integers.
  3625. integer function sum(n)
  3626. \Tab integer n;
  3627. integer k,s;
  3628. s = 0;
  3629. for(k=1; k<=n; k++) s += k;
  3630. return s;
  3631. @ We'll do the I/O in C.
  3632. @<C@>=
  3633. see(pn,ps)
  3634. \Tab int *pn,*ps;
  3635. printf("sum(%d) = %d\\n",*pn,*ps);
  3636. \endcomment
  3637. \dsubsubsection Automatic insertion material. ^^[automatic insertion]
  3638. ^^[declarations!automatic insertions after]
  3639. ^^[insertion!automatic] 
  3640. It is often desirable to include common material at
  3641. the beginning of each program unit, such as the phrase ``\.{implicit
  3642. none}''.  
  3643. Since \Ratfor\ is aware when a program unit begins, it is
  3644. feasible to automate such insertions.  The material to be inserted is
  3645. indicated by a special notation that extends the syntax of a \WEB\ macro
  3646. definition, as follows:
  3647. {\codemode
  3648. @m[\It{ctrl-list}] \It{macroname} \It{macro text}
  3649. \noindent Here the characters in the \It{ctrl-list} between the square
  3650. brackets signify for which 
  3651. kind of program unit the material is to be inserted; they
  3652. may be one or more of the following:
  3653. $$\vbox{\halign{\hfil\tt#&\ ---\ #\hfil\cr
  3654. b & \&{block data}\cr
  3655. f & \&{function}\cr
  3656. i & \&{interface}\cr
  3657. m & \&{module}\cr
  3658. p & \&{program}\cr
  3659. s & \&{subroutine}\cr
  3660. * & All of the above.\cr
  3661. Thus, if you say
  3662. {\codemode
  3663. @m[pfs] AUTO implicit none
  3664. \noindent the text ``\.{implicit none} will be inserted on the lines
  3665. immediately following every \&{program}, \&{function}, and \&{subroutine}
  3666. declaration.  (There is at present no way to prevent this insertion for a
  3667. particular program unit; it is either all or none.)
  3668. At present, 
  3669. you cannot stack automatic material for a particular program unit.  Thus,
  3670. after the statements
  3671. {\codemode
  3672. @m[pfs] AUTO1 implicit none
  3673. @m[f] AUTO2 implicit integer[i-n]
  3674. \noindent functions will begin with the text ``\.{implicit integer[i-n]}''
  3675. while the main program and subroutines will begin with ``\.{implicit
  3676. none}.''  (In the future, such stacking may be allowed.)
  3677. Note that there is nothing special about the macro names used in these
  3678. extended definitions.  Thus, in the above example one could have replaced
  3679. \\{AUTO1} by~\\{X} and \\{AUTO2} by~\\{Y} and achieved precisely the same
  3680. effect.  
  3681. \dsubsubsection Semicolons.
  3682. We now return to the issue of semicolons. ^^[semicolons]
  3683. \It{It is highly recommended that the complete free-form
  3684. syntax, ^^{syntax!free-form}
  3685. with semicolons as statement terminators, be used for all new code.}
  3686. However, it is recognized that an intermediate step may expedite conversion
  3687. of existing \Fortran\ codes. One can initiate an \It{auto-semi} mode with
  3688. the command-line option `\.{-;}'. In this mode, the expected \Ratfor\ syntax
  3689. is midway between \Fortran's and~C's.
  3690. The auto-semi mode ^^:mode!auto-semi:
  3691. is almost free-form syntax, except that carriage returns
  3692. end statements when the line is not ``obviously continued''. By definition,
  3693. a statement is obviously continued ^^:statement!obviously continued:
  3694. if it ends with any of the following
  3695. characters between double quotes: ``\.{+-*=\{\}\^\&|(:><,}''. In this case,
  3696. \WEB\ just goes on to the next line and continues to read. Otherwise, the
  3697. input driver terminates the statement with a semicolon, then ships it off
  3698. to the innards of \WEB. (This clarifies why the character '\.\}' is part of
  3699. the previous list: ``Obviously continued'' really means ``don't end this
  3700. line with a semicolon.'')  Continuation can be forced by ending a line with
  3701. a backslash; the backslash is discarded. (For compatibility with previous
  3702. \Ratfor\ implementations, a trailing underscore will also continue a line
  3703. except when it is part of an identifier; however, its use is definitely not
  3704. recommended.) One implication of these rules is that in the auto-semi mode
  3705. no semicolon should end the first line of a \&{do}; say
  3706. {\codemode
  3707. do i=1,n
  3708. \Tab a(i) = i
  3709. \noindent (Neither statement is obviously continued; the input driver will
  3710. supply semicolons for both.)
  3711. \[According to these rules, lines such as `\.{for(...)}' will be terminated
  3712. by a semicolon. In free-form syntax, such a semicolon would be incorrectly
  3713. interpreted as
  3714. a null statement. In the auto-semi mode, however, a special check is made
  3715. for such a supplied semicolon, which is discarded if present. Thus, the
  3716. \Ratfor\ syntax behaves consistently in both syntax modes.\]
  3717. In the auto-semi mode, an additional commenting style is allowed: anything
  3718. between `\.{\#}' and the end of the line denotes a comment. 
  3719. ^^{comment!Ratfor:\RATFOR}
  3720. This is changed
  3721. by the input driver into a standard C-style comment. However, it is
  3722. recommended that this \Ratfor\ commenting style be avoided; \It{it will
  3723. probably be allowed to die with the next major release}.
  3724. \ddsubsubsection \FWEB\ {\it sans} Ratfor. ^^[Ratfor:\RATFOR!deleting]
  3725. \Ratfor\ is a self-contained subset of \FWEB.  It is possible to create
  3726. \FWEB\ processors that do not contain most of the code associated with
  3727. \Ratfor\ and are therefore smaller.  This may be relevant for users of
  3728. personal computers.  See the installation notes in
  3729. \.{INSTALL\_FWEB.tex} for more information. ^^{\>{INSTALL\UL FWEB.tex}}
  3730. Once again, it is recommended that if you are a \Fortran\ programmer you
  3731. seriously consider \Ratfor.  It will make your life simpler and your
  3732. documentation superior.
  3733. The \Ratfor\ commands are summarized in Appendix~L.
  3734. ^^)Ratfor:\RATFOR)
  3735. \section ADDITIONAL LANGUAGES.[10.2]
  3736. In addition to the principal supported languages of~C, \Cpp, \Fortran, and
  3737. \Ratfor, several other languages are supported at various levels of
  3738. experimental development:
  3739. \subsection TEX mode. ^^(TEX mode(
  3740. \parinserto{2}{5}{0.4}
  3741. ``\FWEB\ offers restricted support for tangling and weaving \TeX\ code.''
  3742. As an experiment,  \FWEB\ offers restricted support for tangling and
  3743. weaving \TeX\ code.  This provides a superior way of maintaining and
  3744. documenting \TeX\ input files, for example macro packages such as
  3745. \.{fwebmac}. ^^{\>{fwebmac}}  
  3746.  One selects the \.{\TeX} language with the command~\atcmd{Lx}.  \FTANGLE\
  3747. will write its \TeX-language output into a file 
  3748. with the extension~\.{.sty}; that can be overridden by the style-file
  3749. option ``\.{suffix.TEX}''.
  3750. \FWEAVE\ will, as usual, create a file with the
  3751. extension \.{.tex}.  As an example, \.{fwebmac} itself is now maintained
  3752. with \FWEB. \FTANGLE\ has been used to create the ``executable'' (i.e.,
  3753. \TeX-compatible) file \.{fwebmac.sty} ^^{\>{fwebmac}!\>{.sty}}
  3754. from the master file \.{fwebmac.web}. ^^{\>{fwebmac}!\>{.web}}
  3755. This explains why \FWEAVE's \.{tex}
  3756. output files begin with the command ``\.{\\input fwebmac.sty}'' instead of just
  3757. ``\.{\\input fwebmac}''.  The latter would incorrectly read in \.{fwebmac.tex},
  3758. ^^{\>{fwebmac}!\>{.tex}}
  3759. which is \FWEAVE's output intended for typesetting.
  3760. In \TeX\ mode, \TeX-like comments (begun with~'\.\%', or more precisely
  3761. begun with any character whose category code is~14) are displayed in the
  3762. standard C-style format, except that if the last character on the line
  3763. is~'\.\%' it is displayed as is. If several adjacent lines consist solely of
  3764. \TeX-like comments, they are concatenated into one long comment.
  3765. Actual spaces in the source are displayed as~'\.\ ', with two exceptions.
  3766. First, tabs in the source are turned into invisible spaces.  Second, spaces
  3767. after multi-character control sequences are also printed as invisible spaces.
  3768. If this is not done, the output tends to become
  3769. extremely dense with the '\.\ '~symbol.
  3770. Note that a full-featured implementation of
  3771. \WEB\ processing for \TeX\  is quite difficult because \TeX\ can, for
  3772. example, change 
  3773. category codes on the fly from within very complicated macro constructions.
  3774. A truly general \WEB\ for \TeX\ should probably be completely integrated
  3775. into \TeX\ itself.  This daunting possibility is far beyond the scope of the
  3776. present \FWEB\ project.  However, it is possible to give \FWEB\ some help
  3777. and thus deal with a variety of circumstances.  In particular, one can force
  3778. \FWEB\ to change the category code of a character.  When \FWEB\ starts up,
  3779. it has assigned default category codes to each ASCII character---for
  3780. ^^{ASCII!category codes for}
  3781. example, the default category code of~'\.\\' is~0; that of~'\.A' is~11;
  3782. that of~'\.\%' is~14.  To change the category code, say in the definition
  3783. section
  3784. {\codemode
  3785. @f `\It{\TeX char} \It{new}_\It{cat}_\It{code}
  3786. \noindent where here, as when changing category codes in \TeX, \It{\TeX
  3787. char} has one of the forms~`$c$', `\.\\$c$', or~`\.{\^\^$c$}', $c$~being a
  3788. visible ASCII character. For example, the command
  3789. {\codemode
  3790. @f `! 14
  3791. \noindent will make the exclamation point also function as a comment
  3792. character.
  3793. At this early stage of development, the \It{only} thing that is guaranteed
  3794. is that \.{fwebmac.sty} will be created correctly from \.{fwebmac.web}.
  3795. Feel free to experiment with \FWEB's \TeX\ language, but don't expect
  3796. perfection yet.  However, suggestions are welcome.
  3797. A sample of woven output from the \TeX\ mode may be found in
  3798. \.{fwebmac.tex}, which is typeset in Appendix~F.
  3799. ^^)TEX mode)
  3800. \subsection MAKE mode. ^^(MAKE mode(
  3801. Someday \FWEB\ may also understand the syntax of \Unix\ \.{make} files.
  3802. ^^)MAKE mode)
  3803. \Knuth
  3804. \section CONTROL CODES.[11.100] ^^(control codes( ^^[commands!control codes]
  3805. We have seen several ^{magic} uses of~\atcmd{} signs in \.{WEB} files, and it
  3806. is time to make a systematic study of
  3807. these special features. A \.{WEB} {\sl control code\/}
  3808. ^^:control codes:
  3809. is a two-character combination of which the first is `\.@'. \[(The only
  3810. exceptions are the three-character combinations~\atcmd{/*} and~\atcmd{//}.)\]
  3811. Here is a complete list of the legal control codes. (Some of these codes
  3812. can be changed by the user, although this is not recommended; see the
  3813. section below on the style file.)  The 
  3814. abbreviations~$L$, $T$, $C$, $M$, $Co$, $S$, and/or~$H$ following each code
  3815. indicate 
  3816. whether or not that code is allowable in limbo~($L$), in \TeX\ text~($T$),
  3817. in \[code\] text~($C$), in module names~($M$), in comments~($Co$), 
  3818. in strings~($S$), and/or in change files~($H$).  A bar over such a letter
  3819. means that the control code 
  3820. terminates the present part of the \.{WEB} file; for example, 
  3821. $\overline L$~means that this control code ends the limbo material before
  3822. the first module.  (A shorter summary of the control codes is presented in
  3823. Appendix~L.) 
  3824. \gdef\@#1(#2)[#3] {\subsection\cc{@#1}\kern1em(#2).\par
  3825. %\yskip
  3826. %\hangindent 2em
  3827. %\noindent\.{@#1\unskip \spacefactor1000{ }}
  3828. \noindent
  3829. %\kern2em
  3830. $[#3]$\quad}
  3831. %\parindent0pt
  3832. %\everypar{\hangindent 2em\kern2em}
  3833. \gdef\cc#1{{\tt #1}}
  3834. \gdef\oP{\overline C}
  3835. \gdef\oT{\overline T}
  3836. \@@(the character '\cc{@}')[Co,L,M,C,S,T] ^^:\>{@@}: 
  3837. A double \.@ denotes the \hl{single character~`\.@'}. 
  3838. This is the only control code that is legal in comments and in strings.
  3839. \[For example, to get the output `\.{"Is there a missing @z?"}', one must
  3840. type in the 
  3841. \WEB\ source file `\.{"Is there a missing @@z?"}'. This is also one of the
  3842. few control 
  3843. codes that is legal in limbo (the only others being the language
  3844. commands~\atcmd{c}, \atcmd{r}, \atcmd{n}, and~\atcmd{L\It{l}}, and the
  3845. ignorable commentary commands~\atcmd{z} and~\atcmd{x}.)\]
  3846. \@|(literal vertical bar [\TeX\ text])[Co,T] ^^:\>{@"|}: ^^:vertical bar,
  3847. literal: 
  3848. In \TeX\ text, this affords a way of inserting the \hl{vertical bar}~`\.|'.
  3849. This is particularly useful within \LaTeX's \.{verbatim} environment.
  3850. ^^{environment!verbatim}
  3851. For example, 
  3852. {\codemode
  3853. \\begin\{verbatim\}
  3854. Consider the expression @|x != y@|.
  3855. \\end\{verbatim\}
  3856. \noindent Without the~\.{@}s, \WEAVE\ would translate the bars and the
  3857. enclosed material into the \TeX\ macros appropriate for code mode.
  3858. In code text, this command is instead an optional line break in an
  3859. expression.  See the discussion below.
  3860. \@\SP(begin unstarred module)[\overline L,\oP,\oT] ^^:\>{@\ }: 
  3861. ^^:module!beginning!unstarred:
  3862. This denotes the beginning of a \hl{new (unstarred) module}.
  3863. ^^{module!unstarred}
  3864. A tab mark or end-of-line (carriage return)
  3865. is equivalent to a space when it follows an \.@ sign.
  3866. \comment
  3867. \parinsert{2}{3}{0.4}
  3868. ``The very first module should be starred.''
  3869. \endcomment
  3870. \@*(begin a starred module)[\overline L,\oP,\oT] ^^:\>{@*}: 
  3871. ^^:module!beginning!starred:
  3872. This denotes the beginning of a \hl{new starred module},
  3873. ^^{module!starred} 
  3874. i.e., a module that begins a new major group. The title
  3875. of the new group should appear after the~\atcmd{*}, followed by a period.
  3876. \[This title will be entered in the table of contents.\] As explained
  3877. above, \TeX\ control sequences should be avoided in such titles unless they
  3878. are quite simple. When \.{WEAVE} and \.{TANGLE} read an~\atcmd{*}, they print
  3879. to the terminal an asterisk followed by the current module number, so that
  3880. the user can see some indication of progress. The very first module should
  3881. be starred.
  3882. \endKnuth
  3883. If the group title is immediately followed by a non-negative integer~$n$,
  3884. the title is considered to be of level~$n$, where $n = 0$ corresponds to a
  3885. major section, $n = 1$ corresponds to a primary subsection, and so on.  The
  3886. \.{fwebmac} macros can be defined to treat these levels in different
  3887. ways---for example, the appearance of a subsection entry in the table of
  3888. contents can be modified by appropriate macro definitions.
  3889. \Knuth
  3890. \@A(begin code part of unnamed module)[\oP,\oT] ^^:\={@a}{@A}: 
  3891. ^^:module!part!code:
  3892. \hl{The \[code\] part of an unnamed module}  
  3893. ^^{module!unnamed}
  3894. begins with~\atcmd{A} (or~\atcmd{a}; see below).
  3895. \It{(This is a change from the original \WEB, which
  3896. used~\atcmd{p} (for \PASCAL) and from \CWEB, which used~\atcmd{c}. In
  3897. designing \FWEB, it was felt most logical to reserve 
  3898. these commands for actually switching into a particular language; this is an
  3899. operation distinct from beginning the unnamed module.)}
  3900. This causes \.{TANGLE} to append the following  code
  3901. to the initial program text~$T_0$ as explained above. The \.{WEAVE}
  3902. processor does not cause an~\atcmd{A} to appear explicitly in the \TeX\
  3903. output, so if you are creating a \.{WEB} file based on a \TeX-printed
  3904. \.{WEB} documentation you have to remember to insert~\atcmd{A} in the
  3905. appropriate places of the unnamed modules.
  3906. \endKnuth
  3907. \@a(begin code part of unnamed module; mark first non-reserved word)%
  3908. [\oP,\oT] ^^:\>{@a}: Equivalent to~`\atcmd{A@[}'. That is, the first
  3909. non-reserved word following the~\atcmd{a} will be marked as defined in this
  3910. module.  This convention helps circumvent the forward-referencing problem;
  3911. see the discussion about ``Forward references'' below.
  3912. \@b(insert breakpoint command)[C] ^^:\>{@b}: ^^{commands!breakpoint}
  3913. ^^{breakpoint command} 
  3914. When the ^{debugging} mode is turned on (which means when 
  3915. the \.{\_BP} macro has been defined from the command line; see discussion
  3916. below), the \atcmd{b}~command means \hl{insert a breakpoint command}.
  3917. When debugging is off, this command is ignored.
  3918. \@c(set language to~C)[L,C,T,H] ^^:\>{@c}: ^^:language!setting!C:
  3919. The \atcmd{c}~command means \hl{set the current language to~C}.
  3920. ^^{language!C} 
  3921. \It{It does not mean begin the unnamed module, as
  3922. it did in Levy's \CWEB.} (See the detailed discussion of language
  3923. commands for more information.) 
  3924. \@c++(set language to~\Cpp)[L,C,T,H] ^^:\>{@c++}: ^^:language!setting!\Cpp:
  3925. The \atcmd{c++}~command means \hl{set the current language to~\Cpp}.
  3926. ^^{language!\Cpp}
  3927. \@D(define outer macro)[\oP,\oT] ^^:\={@d}{@D}: \hl{Definitions of outer
  3928. macros} ^^:macro!outer!defining: 
  3929. begin with~\atcmd{D} (or~\atcmd{d}; see below), followed by
  3930. the code text for the macro syntax appropriate for the language currently
  3931. in force. These definitions must be made in the definition
  3932. part,  ^^{definition!part} 
  3933. which consists of any number of
  3934. macro definitions (beginning with~\atcmd{d} \[or~\atcmd{m}\]), format
  3935. definitions (beginning 
  3936. with~\atcmd{f}), \[preprocessor commands (beginning with~\atcmd{\#}), limbo
  3937. text 
  3938. definitions (beginning with~\atcmd{l}), operator overloading instructions
  3939. (beginning with~\atcmd{v}), identifier overloading instructions (beginning
  3940. with~\atcmd{W}), and language commands\], intermixed in any order.
  3941. For \Fortran, the syntax should be that for the
  3942. \.{m4} preprocessor; for~\C, it should be that of the C~preprocessor.
  3943. For \Ratfor, outer macros should never be used, since \TANGLE's
  3944. macro-processing capabilities are intended to provide a self-contained
  3945. means of getting directly from the \WEB\ source to compilable \Fortran.
  3946. Outer macros are simply copied to the beginning of the appropriate output
  3947. file. If the text of the macro contains an identifier that is a \WEB\
  3948. macro, \It{that macro will be expanded}.
  3949. The companion command~\atcmd{u} undefines an outer macro.
  3950. \@d(define outer macro; mark macro name defined)[\oP,\oT] ^^:\>{@d}:
  3951. Equivalent to `\atcmd{D@[}'.  See discussion about ``Forward references''
  3952. below. 
  3953. \Knuth
  3954. \comment
  3955. \parinsert{4}{3}{0.4}
  3956. ``Module names can be formatted.''
  3957. \endcomment
  3958. \@f(format identifier)[\oP,\oT] ^^:\>{@f}: 
  3959. ^^:definition!format: ^^:formatting!identifiers: ^^:formatting!module names:
  3960. \hl{Format definitions} begin with~\atcmd{f}; they cause 
  3961. \.{WEAVE} to treat identifiers or module names in a special way when they
  3962. appear in 
  3963. \[code\] text. The general form of a format definition is 
  3964. \atcmd{f} \|l \|r, followed by an optional comment, where \|l is an identifier \[or a 
  3965. module name\] and~\|r is an
  3966. identifier; \.{WEAVE} will subsequently treat~\|l as it
  3967. currently treats~\|r. \[The formatting is \It{language-specific}; it only
  3968. applies to identifiers used in the language  in force at the point the
  3969. format statement is encountered.\]
  3970. This feature allows a \.{WEB} programmer to invent
  3971. new reserved words and/or to unreserve some  reserved
  3972. identifiers. \[Note that module names can be formatted. 
  3973. ^^{formatting!module names}
  3974. By default,
  3975. module names are interpreted as expressions. However, sometimes you use
  3976. them in other contexts, such as replacing a bunch of type specifications.
  3977. In this situation, you should say something like ``{\tt @f @<Common blocks@>
  3978. common}''.\] 
  3979. \endKnuth
  3980. An extension of the \atcmd{f}~command is used when the language is \.{TEX}
  3981. to change the category code of a character. The format is `\atcmd{f}
  3982. \.\`\It{\TeX char} \It{new\_cat\_code}'.  See the discussion of \TeX\ mode
  3983. for more details. 
  3984. \@i(include a file)[\It{web file}] ^^:\>{@i}: ^^:file!including:
  3985. \Levy: The web file itself can be a combination of several files.
  3986. When \WEAVE\ or \TANGLE\ are reading a file and encounter the control
  3987. code~\atcmd{i} at the beginning of a line, they interrupt their reading and
  3988. start reading the file named after the~\atcmd{i}, much as the
  3989. C~preprocessor does when it encounters an \&{\#include} line. After the
  3990. included file is done, they go back to the next line of the original file.
  3991. The file name following~\atcmd{i} can be surrounded by double quotes or
  3992. not; it should be made up of visible ASCII characters only, not including
  3993. double quotes.  Include files can nest, with level~0 being the primary
  3994. level associated with the source \WEB\ file.  Optionally, a second file
  3995. name also may be given.  Just as on the command line, this names the
  3996. ^{change file} associated with the new include file.  This name is in
  3997. effect for all higher levels of nesting, but is forgotten when the include
  3998. file ends and control reverts to the next lower level.  If no change file
  3999. is specified at any level, the one in effect at the time of the include
  4000. continues to be used.  Automatic file-name completion is done when the
  4001. command-line option~`\.{-e}' is in effect; otherwise, you must give the
  4002. complete name of the file, including extensions such as `\.{.web}'.
  4003. \FWEAVE\ will print the name
  4004. of the current include file at the beginning of each section.  However,
  4005. note that there is no need that a file included by~\atcmd{i} consist of a
  4006. complete module.  Include files may be included anywhere, in either the
  4007. \TeX\ part, the definition part, and/or the code part; they may, in
  4008. principle, consist of arbitrary fragments of code.  Whenever possible,
  4009. however, it is best to stick to complete modules for included files.
  4010. By default, include files are searched for in the current directory.
  4011. However, if the environment variable \\{FWEB\_INCLUDES} is defined, then
  4012. its contents are interpreted as a colon-delimited list of paths to be
  4013. searched for the include file.  (The same format as \Unix' \\{PATH}
  4014. variable is used.)  In addition, whether or not that variable
  4015. is defined, one can append to the include path list by means of the
  4016. `\.{-I}'~command-line option. ^^{\={-i}{-I}}
  4017. \It{(The following is rendered obsolete by the previous paragraph; the
  4018. feature will probably be deleted in a future release.)}
  4019. File names in \atcmd{i}~commands may begin with a prefix followed by a colon,
  4020. as in ``\.{LN:file\_name}''. The intention is that \.{LN}~behaves like a
  4021. logical name under~VMS. In fact, under~VMS \.{LN}~is just left alone.
  4022. However, under \Unix\ \.{LN}~is assumed to be an environment variable and is
  4023. expanded. Thus, if one says ``\.{setenv LN /fweb}'' then
  4024. ``\.{LN:file\_name}'' will expand to ``\.{/fweb/file\_name}'' (note that
  4025. the last slash was inserted automatically).  This mechanism is intended to
  4026. enhance portability of \WEB\ sources between various operating systems.
  4027. \@I(optionally include a file)[\It{web file}] ^^:\={@i}{@I}: This command is
  4028. like~\atcmd{i}, except that in 
  4029. special cases \FWEAVE\ will not process it completely.  The special cases
  4030. are when the command-line options~`\.{-i}' or~`\.{-i!}' are used. In
  4031. particular, when `\.{-i}'~is in effect, files included via~\atcmd{I} will be
  4032. processed but not printed in the woven output.  (This helps save trees.)
  4033. See the description of the command-line options below for more information
  4034. about this \It{experimental} feature. 
  4035. \@L(set language)[L,C,T,H] ^^:\={@l}{@L{\it l}}: ^^:language!setting:
  4036. The command~\atcmd{L$l$} sets the language to~$l$, where $l \in
  4037. \{\.c,\.n,\.r,\.x\}$.  Optional arguments to this command enable one to
  4038. invoke~\Cpp, \Fortran--90, or \Ratfor--90.  See the detailed discussion of
  4039. languages above.
  4040. \@l(specify limbo text)[\oP,\oT] ^^:\>{@l}: ^^:limbo!text:
  4041. This command specifies
  4042. \hl{limbo text}.  It must 
  4043. be followed by a double-quoted string, in which special characters are
  4044. escaped just as in~\C.  The contents of that string are
  4045. written out verbatim by \FWEAVE\ just before the limbo section is copied to
  4046. the output.  Thus, if there was just one limbo text command of the form
  4047. {\codemode
  4048. @l "\\\\def\\\\greeting\{Hello\}\\n\\\\def\\\\done\{Goodbye\}"
  4049. \noindent the output \.{tex}~file would begin with the lines
  4050. {\codemode
  4051. \\input fwebmac.sty
  4052. % --- Limbo text definitions from @l ---
  4053. \\def\\greeting\{Hello\}
  4054. \\def\\done\{Goodbye\}
  4055. \noindent Note the use of C-like escape sequences such as~`\.{\\\\}'
  4056. or~`\.{\\n}'. 
  4057. \@M(define a \WEB\ macro)[C,\oT] ^^:\={@m}{@M}: ^^:macro!inner!defining:
  4058. The \atcmd{M} (or~\atcmd{m}; see below) command denotes a \hl{\WEB\ 
  4059. macro}. \WEB\ 
  4060. macros have exactly the same syntax as C~macros (including arguments), 
  4061. but they are expanded when
  4062. \FTANGLE\ outputs the code. Just as in~C, the construction is expanded again
  4063. and again until nothing remains to be expanded. [The ANSI~C constructions
  4064. `\&\#' (``stringize'') and~`\&{\#\#}' (``token paste'') are supported, as
  4065. are certain extensions such as the ability to handle variable numbers of
  4066. arguments.] 
  4067. On input, the preprocessor understands all macros that have been defined up
  4068. to the current point in the file, so they can be used in statements such as
  4069. `\.{@\#if(MACRO)} \It{block\_of\_code} \.{@\#endif}' to selectively reject
  4070. or retain fragments of code.  Usually, \.{@m}~commands should appear in the
  4071. definition section, but they are also permitted in the code section, where
  4072. they are called \It{deferred macros}.  See the section on `Macros' for more
  4073. details. 
  4074. \@m(define a \WEB\ macro; mark macro name defined)[C,\oT] ^^:\>{@m}:
  4075. Equivalent to `\atcmd{M@[}'.  See the discussion about ``Forward
  4076. references'' below.
  4077. \@n(set language to \Fortran)[L,C,T,H] ^^:\>{@n}:
  4078. ^^:language!setting!Fortran--77\actual\FORTRAN--77: 
  4079. The \atcmd{n}~command means \hl{set the 
  4080. current language to~\Fortran}. ^^{language!Fortran:\FORTRAN}
  4081. (See the more detailed discussion of
  4082. language commands for more information.) One may question the choice of
  4083. symbol here. Unfortunately, `\.f'~was already in use, denoting formatting;
  4084. hence, we use the \It{last} letter of the language name: fortra\.N, \.C,
  4085. ratfo\.R.  With no argument, \Fortran--77 is selected.  The command
  4086. \atcmd{n9}~selects \Fortran--90.
  4087. \@O(open new output file with global scope)[C] ^^:\>{@O}:
  4088. ^^:file!output!opening new:
  4089. The \atcmd{O}~command \hl{changes the name of the output file} for tangled
  4090. code, during the output in phase~2.  At present, it may appear only in the code
  4091. section.  
  4092. White space is skipped after the~\atcmd{O}.  The next run of
  4093. non-white characters is interpreted as a complete file name, including
  4094. extension.  Any remaining text on the line is skipped.  The upper-case form
  4095. of this command has \It{global} scope---that is, the name change remains in
  4096. effect until the next \atcmd{O}~command, if any.  (The lower-case form has
  4097. local scope and is probably more useful; see below.)  At present, this
  4098. command has no effect for 
  4099. \FWEAVE.  The purpose of this command is to allow very large codes to be
  4100. tangled into several output files in cases where the compiler may have
  4101. limitations on the size of the source file it can process.
  4102. Note that since \atcmd{d}~commands are collected during phase~1, they are
  4103. at present oblivious to any~\atcmd{O} or \atcmd{o}~commands;
  4104. \atcmd{d}~definitions will always be written into the first file open for a
  4105. particular language.  (In the future, this may be generalized.)
  4106. \@o(open new output file with local scope)[C] ^^:\>{@o}:
  4107. ^^:file!output!opening new:
  4108. The \atcmd{o}~command \hl{changes the name of the output file} for tangled
  4109. code, during the output in phase~2.  The rules are the same as for the
  4110. \atcmd{O}~command described above, except that \atcmd{o}~has \It{local}
  4111. scope.  That is, the command behaves in the same way as does a local
  4112. language change: output is diverted to the new file \It{for the duration of
  4113. the current section only}.  When the next section begins, output reverts to
  4114. the global output file, as known at the beginning of the first module.
  4115. The purpose of this command is to generate several different kinds of files
  4116. from a single source file.  For example, let the \WEB\ file be called
  4117. \.{test.web}.  Then one could say
  4118. {\codemode
  4119. @ Demonstration of the \\.\{@o\} command.
  4120. @o test.h
  4121. int i; // This code goes into \\.\{test.h\}.
  4122. @ The next code goes into \\.\{test.c\}.
  4123. main()
  4124. \@r(set language to \Ratfor)[L,C,T,H] ^^:\>{@r}:
  4125. ^^:language!setting!Ratfor--77\actual\RATFOR--77: 
  4126. The \atcmd{r}~command means \hl{set the 
  4127. current language to~\Ratfor}. ^^{language!Ratfor:\RATFOR}
  4128. With no argument, \Ratfor--77 is selected.  The command \atcmd{r9}~selects
  4129. \Ratfor--90.  (See the detailed discussion of language commands for
  4130. more information.)
  4131. \@u(undefine an outer macro)[\oP,\oT] ^^:\>{@u}: ^^:macro!outer!undefining:
  4132. This command \hl{undefines an outer macro}.   
  4133. ^^{macro!outer} 
  4134. It should be used in the definition part only. ^^{definition!part}
  4135. See the discussion of~\atcmd{d} for more discussion.
  4136. \@v(overload an operator)[\oP,\oT] ^^:\>{@v}: ^^:operators!overloading:
  4137.  The \atcmd{v}~command allows one to give \FWEAVE\ information about
  4138. \hl{operator overloading}, an important feature of both~\Cpp\ and
  4139. \Fortran--90.  The syntax of this command is ``\.{@v \It{new}\_\It{op}
  4140. "\It{replacement \TeX\ text}" \It{old}\_\It{op}}'' and is
  4141. described  in detail in the section on ``Operator overloading'' above.
  4142. \@W(overload an identifier)[\oP,\oT] ^^:\>{@W}: ^^:identifiers!overloading:
  4143. The \atcmd{W}~command allows one to change the appearance of identifiers.
  4144. This command has several variants:  ``\.{@W \It{identifier}
  4145. "\It{replacement \TeX\ text}"}'', ``\.{@W \It{identifier}
  4146. \\\It{newmacro}}'', and ``\.{@W \It{identifier} .}''.  These are described
  4147. in detail in the section on ``Identifier overloading'' above.
  4148. \@x(terminate commentary section; begin old material in change file)[L,H]
  4149. ^^:\>{@x}: ^^:ignorable material!terminating: 
  4150. This terminates the opening commentary section of a 
  4151. file.  See the discussion of~\atcmd{z} below. ^^{commentary!invisible}
  4152. This command is also used in change files to begin the old material; see
  4153. the separate discussion of change files.
  4154. \@y(terminate old material in change file)[H] ^^:\>{@y}: This is used in
  4155. change files to terminate the old 
  4156. material and to begin the new material.  See the separate discussion of
  4157. change files. 
  4158. \@z(begin commentary section; end changed material)[L,H] ^^:\>{@z}:
  4159. ^^{commentary!invisible} ^^:ignorable material!beginning:
  4160. If a file begins with~\atcmd{z} in its very first two
  4161. positions, everything up to and including a line beginning with~\atcmd{x} is
  4162. skipped.  This feature allows one to insert commentary such as date,
  4163.     author, etc.\ that will not be printed or otherwise processed.  
  4164. This command is also used in change files to end the changed material; see the
  4165. separate discussion of change files.
  4166. \@'(convert character to ASCII integer)[C] ^^:\>{@'}:
  4167. ^^:ASCII!converting to:
  4168. A construction of the form ``\.{@'$c$'}'' \hl{converts the single
  4169. character~$c$ to an integer representing its ASCII value}.  The character
  4170. can be represented in any of the standard forms:  for example \.{'a'},
  4171. \.{'\\141'}, and~\.{'\\x61'} are all equivalent.  In~C and~\Cpp, the
  4172. character is converted into octal---e.g., \.{@'a'}~$\to$~\.{0141}. In the
  4173. \Fortran-like languages it is converted into an integer of base~10---e.g.,
  4174. \.{@'a'}~$\to$~\.{97}.  
  4175. \@"(convert string to ASCII)[C] ^^:\>{@""}:
  4176. ^^:ASCII!converting to:
  4177. A construction of the form ``\.{@"$c_1c_2\dots c_n$"}'' \hl{converts each
  4178. character in 
  4179. the string to an integer representing its ASCII value}, returning a
  4180. construction appropriate for initializations in the current language.  In~C
  4181. or~\Cpp, the result is a string with the characters replaced by the
  4182. appropriate octal values---e.g., $\.{@"a\\376b\\n"} \to
  4183. \.{"\\141\\376\\142\\12"}$. 
  4184. For \Fortran-like languages, the implementation is experimental and subject
  4185. to change.  Presently, it works as follows.
  4186. First, the \atcmd{}~is stripped away, leaving the string.  If the value
  4187. of the style-file 
  4188. field \.{ASCII\_fcn} is the null string, then the string is unchanged.  If
  4189. \.{ASCII\_fcn} is not null, this field is used as the name
  4190. of a function to be called with the ASCII string as argument.  Thus, the
  4191. default value of \.{ASCII\_fcn} is \.{"ASCIIstr"}.  Unless this is changed
  4192. in the style file, then in \Fortran\ the command ``\.{@"a\\376b\\n"}'' will
  4193. tangle to ``\.{ASCIIstr('a\\376b\\n')}''.
  4194. \@{[}(mark next identifier as defined here)[C,H] ^^:\>{@[}: 
  4195. ^^:identifiers!marking as defined:
  4196. This command has two uses.  First, if it appears in a 
  4197. change file in the first two positions of the line, it signifies a shift
  4198. into code mode; see the separate discussion of change files.
  4199. Otherwise, it says that the next \It{non-reserved} identifier should be marked
  4200. as being defined in this section.  Identifiers thus marked are subscripted
  4201. ^^{subscripts, module number}
  4202. in the woven output with the number of the section in which they were
  4203. defined.  Usually, the identifier is a function name.  When \FWEAVE's
  4204. syntax analyzer recognizes a function in phase~2, it marks the function
  4205. name automatically.  However, only subsequent references to that function
  4206. are marked.  Additional mechanisms exist to handle the problem of forward
  4207. referencing.  For example, the commands~\atcmd{a}, \atcmd{d}, and~\atcmd{m}
  4208. issue implicit~\atcmd{[}s. See the more detailed discussion about ``Forward
  4209. references to identifiers'' in the section on ``Additional Features'' below.
  4210. \@](shift out of code mode)[H] ^^:\>{@]}: This command also has two uses.
  4211. If it appears in a 
  4212. change file in the first two positions of the line, it signifies a shift out of
  4213. code mode; see the separate discussion of change files.
  4214. (Otherwise, its use is experimental and not supported yet.)
  4215. \@`(\It{reserved})[C,H] 
  4216. \It{This command is experimental.  Please do not use.}
  4217. \Knuth
  4218. \@<(begin a module name)[C,\oT] ^^:\>{@<}: ^^:module!name!beginning:
  4219. A \hl{module name} begins with~\atcmd{<} followed by ^^:module!name:
  4220. \TeX\ text followed 
  4221. by~\atcmd{>}; the \TeX\ text should not contain any \.{WEB} control sequences
  4222. except~\atcmd{@}, unless these control sequences appear in \[code\] text that
  4223. is delimited by \pb. The module name may be abbreviated, after its first
  4224. appearance in a \.{WEB} file, by giving any unique prefix followed by
  4225. `\.{...}', where the three dots immediately precede the closing~\atcmd{>}. No
  4226. module name should be a prefix of another. Module names may not appear in the
  4227. definition part of a module (since the appearance of a module name ends the
  4228. definition part and begins the \[code\] part). \[There are two exceptions
  4229. to this last rule: first, a module name may appear immediately after an
  4230. \atcmd{f} command, thereby allowing module names to be formatted. Second,
  4231. you may use the construction \.{\#<\dots@>} ^^{\>{\PM<...@>}} in a \WEB\
  4232. macro definition to stand for a module name.\]
  4233. \endKnuth
  4234. \@{/*}(begin long verbatim comment)[C] ^^:\>{@/*}: ^^:comment!long!beginning:
  4235. This denotes a long \hl{verbatim comment}  
  4236. ^^:comment!verbatim: ^^{comment!long}
  4237. (terminated by~`\.{*/}'). 
  4238. The idea is that while \TANGLE\ generally throws away all comments,
  4239. stripping down the output to a bare minimum, retaining some comments in the
  4240. output may be helpful for debugging purposes. Therefore, one is allowed to
  4241. preface ordinary C-style comments with an \atcmd{}; such comments will be
  4242. passed through to the output. For~\C, the comment is literally just passed
  4243. along; nothing else happens. For the other languages, care is taken to
  4244. generate a valid comment line. This is particularly annoying for \Fortran--77,
  4245. which does not have the notion of a trailing comment. There, trailing
  4246. verbatim comments are moved to the next line (essentially the inverse of
  4247. what the input driver does). Incidentally, module numbers are automatically
  4248. inserted as verbatim comments into the program, in order to help correlate
  4249. the outputs of \.{WEAVE} and \.{TANGLE} (see Appendix~C\null). To make all
  4250. comments verbatim, use the command-line option `\.{-v}' or put the
  4251. command~`\.{+v}' into your \.{.fweb} file.  ^^{\>{-v}}
  4252. \@{//}(begin short verbatim comment)[C] ^^:\>{@//}:
  4253. ^^:comment!short!beginning: 
  4254. A short \hl{verbatim comment} (terminated by an 
  4255. end-of-line). ^^{comment!verbatim} ^^{comment!short}
  4256. \@\%(ignorable comment)[L,T,C]  ^^:\>{@\PC}: ^^:comment!ignorable:
  4257. \hl{Ignorable comments} are \FWEB's analogs to \TeX\
  4258. comments: Everything from the \atcmd{\%}~command to and including the next
  4259. newline is ignored, for both \FWEAVE\ and \FTANGLE.  Thus, this comment
  4260. does not appear as part of the \FWEAVE's typesetting, in either the \TeX,
  4261. definition, or code part.  It can be useful for hiding text that might be
  4262. used in conjunction with special editors.  It can also be used to suppress
  4263. unwanted newlines that sneak into module definitions.  Those generally
  4264. begin and end with a newline, as indicated:
  4265. {\codemode
  4266. @<\dots@>=\It{newline}
  4267. \Tab .
  4268. \Tab .
  4269. last line of module\It{newline}
  4270. \noindent Especially in \Fortran-77, those newlines may prevent the use of
  4271. the module name as a component of a longer line, for example as an argument
  4272. list of a function:
  4273. {\codemode
  4274. \Tab function f(@<Args@>)
  4275. \noindent To ensure that this example tangles correctly, say
  4276. {\codemode
  4277. @<Args@>=@%
  4278. a,b,c@%
  4279. \comment
  4280. Also, if this command is encountered in
  4281. a \TeX\ part, it ends that part and starts the definition section.  An
  4282. ordinary comment on the next line will then be formatted properly.
  4283. (Otherwise, the comment would be treated as part of the \TeX\ part and
  4284. formatted less desirably.)  Thus, if you wish to begin a definition part
  4285. with a comment, say
  4286. {\codemode 
  4287. @ TeX documentation.  
  4288. @% (Any text here is completely ignored.)
  4289. // This comment is formatted properly. 
  4290. @m ...  
  4291. \endcomment
  4292. \@?(compiler directive)[C] ^^:\>{@?}: ^^:compiler directives!beginning:
  4293. This command begins a one-line \hl{compiler directive}. 
  4294. \FTANGLE\ constructs an output line by first outputting the contents of the
  4295. style field \.{cdir\_start.$l$}, where $l$~is the identifier character for
  4296. the current language.  Then it copies everything between the~\atcmd{!} and the
  4297. next newline.  Consider the C~language as an example.  By default,
  4298. \.{cdir\_start.C} is set to \.{"\#pragma\ "}.  Then the command
  4299. `\atcmd{?help}' is output as ``\.{\#pragma\ help}''.
  4300. \@!(compiler directive)[C] ^^:\>{@"!}: ^^:compiler directives!beginning:
  4301. This is an obsolete form of~\atcmd{?}.  It differs in the way that the text
  4302. following the command is processed.  For~\atcmd{!}, that text is just treated
  4303. as one big string.  For~\atcmd{?}, the text is broken up into tokens.  The
  4304. advantage of this is that argument substitution can occur when \atcmd{?} is
  4305. used in a \WEB\ macro definition.
  4306. \@{(}(begin meta-comment)[C] ^^:\>{@(}: ^^:comment!meta-!beginning:
  4307. The beginning of a ``\hl{meta-comment},'' ^^{comment!meta-} i.e.,
  4308. commented-out code-section material that is supposed to appear in the
  4309. output file, is indicated by \atcmd{(} in the \.{WEB} file.  (Place this
  4310. command in column~1.)  {\bf Note that
  4311. the behavior of this command has been changed beginning with version~1.30.}
  4312. For both processors, this command provides a verbatim channel directly to
  4313. the output; it behaves as a generalized comment.  Its operation is
  4314. controlled by several style-file parameters.  For \FTANGLE, these are
  4315. \.{meta.top.$l$}, \.{meta.prefix.$l$}, and \.{meta.bottom.$l$}, where
  4316. $l$~is a language symbol such as~`\.{N}' for \Fortran.  By default, these
  4317. are defined to generate valid comments for each particular language.  For
  4318. example, the C~defaults are \.{meta.top.C = "/*"}, \.{meta.bottom.C =
  4319. "*/"}, and \.{meta.prefix.C = ""}.
  4320. If they are defined in the style file, then the body of text
  4321. between~\atcmd{(} and~\atcmd{)} is preceded by the contents of \.{meta.top}
  4322. and followed by the contents of \.{meta.bottom}.  Each line of the body of
  4323. text will begin with the contents of \.{meta.prefix}.  Experiment with an
  4324. example to see just what happens.  For \FWEAVE, the parameters are
  4325. \.{meta.begin} and \.{meta.end}; these are defined by default to set up
  4326. appropriate verbatim environments to surround the body of text.  For
  4327. example, in \LaTeX\ (when the `\.{-PL}'~option is used)
  4328. they bracket the text with \.{\\begin\{verbatim\}} and
  4329. \.{\\end\{verbatim\}}.  
  4330. This command may be useful when converting pre-existing \Fortran\ codes
  4331. with comments designed without regard for \TeX's conventions.  The verbatim
  4332. environments will not destroy vertical alignment, nor will they complain
  4333. about the use of special symbols such as~'\.{\$}'.  However, please use
  4334. this command only as a last resort.  For pretty alignments, use \TeX's
  4335. alignment features (e.g., \.{\\halign}) inside a standard \WEB\ command.
  4336. If you want to temporarily comment out a section of code, it is best to use the
  4337. preprocessor commands~\atcmd{\#if} and~\atcmd{\#endif}.  
  4338. \@)(end meta-comment)[C] ^^:\>{@)}: ^^:comment!meta-!ending:
  4339.  The end of a ``meta-comment'' is indicated by~\atcmd{)}. (Place this
  4340. command in column~1.)
  4341. \@\{(suppress breakpoint comment)[C] ^^:\>{@\LB}: ^^:breakpoint
  4342. command!suppressing insertion of:
  4343. In debugging mode (which means when the \.{\_BP} macro 
  4344. has been defined from the command line; see discussion below), this command
  4345. is used to replace the opening brace of a module, and means to suppress the
  4346. default insertion of a breakpoint command just after that brace. This is
  4347. necessary in C~code when the brace is followed by declaration statements.
  4348. To insert the breakpoint later, use~\atcmd{b} at the desired location.
  4349. \Knuth
  4350. \@\AM(join two items)[C] ^^:\>{@\amp}: ^^:joining: 
  4351. The \hl{\.{@\&} [\It{join}] operation}  
  4352. causes whatever is on its left to be adjacent to whatever is on
  4353. its right, in the \[code\] output. No spaces or line breaks will separate
  4354. these two items. However, the thing on the left should not be a semicolon,
  4355. since a line break might occur after a semicolon.  \[(See also the
  4356. \atcmd{+}~command.)\] 
  4357. \endKnuth
  4358. The \It{join} operation should be distinguished from the macro processor's
  4359. \It{paste} operation (\.{\#\#}). Pasting ^^{pasting}
  4360. abuts two things, then \It{retokenizes} the result to obtain a single new
  4361. identifier. Joining simply prevents a space from appearing between two
  4362. objects on output. The difference can be very significant in macro
  4363. processing, where the new identifier that results from the paste might be a
  4364. macro subject to further expansion.  In general, the join operation should
  4365. not be used within \WEB\ macro definitions.
  4366. \Knuth
  4367. \@\^(index entry in Roman type)[C,T] ^^:\>{@\^}:^^:text!control: 
  4368. ^^:index!entry!Roman type: 
  4369. The ``\hl{control text}'' that follows, namely everything up to the
  4370. next~\atcmd{>}, will be  
  4371. entered into the index together with the identifiers of the program; this
  4372. text will appear in Roman type.  ^^{fonts!Roman} For example, to put the
  4373. phrase ``system dependencies'' into the index, you can type `\.{@\^system
  4374. dependencies@>}' in each module that you want to index as system-dependent.
  4375. A control text
  4376. \bdots\ must end on the same line of the \.{WEB} file as it began.
  4377. Furthermore, no \.{WEB} control sequences are allowed in a control text,
  4378. not even~\atcmd{@}. (If you need an \atcmd{}~sign you can get around this
  4379. restriction by typing `\.{\\AT!}'.) ^^:\CS{AT"!}:
  4380. \@.(index entry in typewriter type)[C,T] ^^:\>{@.}: 
  4381. ^^:index!entry!typewriter type: 
  4382.  The ``\hl{control text}'' that follows will be entered 
  4383. into the index in \.{typewriter} \.{type}; ^^{fonts!\>{typewriter}} see the
  4384. rules for \atcmd{\^}, which is analogous.
  4385. \@9(user-defined index entry)[C,T] ^^:\>{@9}: ^^:index!entry!user-controled
  4386. format:  
  4387.  The ``\hl{control text}'' that follows will be entered 
  4388. into the index in a format controlled by the \TeX\ macro~`\.{\\9}', which
  4389. the user should define as desired; see the rules for~\atcmd{\^}, which is
  4390. analogous.  The reference would be made as follows: \.{@9wildcard
  4391. reference@>}. If you wanted your wildcard reference to appear in {\ss
  4392. sans serif} type, you would define~\.{\\9} like this:
  4393. \.{\\def\\9\#1\{\{\\tenss\#1\}\}}. (In earlier versions of \WEB, this command
  4394. was called~\atcmd{:}. However, that is now the pseudo-colon, and although
  4395. \.{@9}~may not look as pretty, it should be easier to remember.)
  4396. \@t(format control text)[C] ^^:\>{@t}: ^^[text!control!putting into hbox]
  4397. The ``\hl{control text}'' that follows, up to the next~\atcmd{>}, will be
  4398. put into a \TeX\ \.{\\hbox} and formatted along with the 
  4399. neighboring program. This text is ignored by \.{TANGLE}, but it can be used
  4400. for various purposes within \.{WEAVE}. For example, you can make comments
  4401. that mix \[code\] and classical mathematics, as in `$\\{size}<2^{15}$', by
  4402. typing `\.{|size < @t\$2\^\{15\}\$@>|}'.  A control text must end on the
  4403. same line of the \.{WEB} file as it began, and it may not contain any
  4404. \.{WEB} control codes.
  4405. \@=(verbatim control text)[C] ^^:\>{@=}: 
  4406. ^^:text!control!passing verbatim to output:
  4407. The ``\hl{control text}'' that follows, up to the next~\atcmd{>}, will be
  4408. \hl{passed verbatim} to the program. 
  4409. \@\_(underline index entry)[C,T] ^^:\>{@\_}: ^^:index!entry!underlining:
  4410. The module number in an index entry will be underlined 
  4411. if \atcmd{\_}~immediately precedes the identifier or control text being
  4412. indexed. This convention is used to distinguish the modules where an
  4413. identifier is defined, or where it is explained in some special way, from
  4414. the modules where it is used. A~reserved word or an identifier of length
  4415. one will not be indexed except for underlined entries. An~\atcmd{\_} is
  4416. implicitly inserted by \.{WEAVE} \[when an identifier is being defined or
  4417. declared---for example, when \WEAVE\ recognizes a function, or in type
  4418. specification statements such as \&{integer} \|i,~\|j\].  It is also
  4419. inserted implicitly just after~\.{@d}, \.{@m}, and~\.{@f}.  Because of
  4420. these implicit insertions, one should rarely need to use \.{@\_}~explicitly.
  4421. \@-(delete index entry)[C] ^^:\>{@-}:
  4422. ^^:index!entry!deleting:
  4423. An identifier that immediately follows an~\atcmd{-} will not appear in the
  4424. index.  
  4425. \@,(insert a thin space)[C] ^^:\>{@,}: ^^:insertion!thin space:
  4426. This control code inserts a \hl{thin space} in \.{WEAVE}'s output; 
  4427. it is ignored by \.{TANGLE}. Sometimes you need this extra space if you are
  4428. using macros in an unusual way, e.g., if two identifiers are adjacent.
  4429. \@/(line break)[C] ^^:\>{@/}:^^{line!break} ^^:insertion!line break:
  4430. This control code causes a
  4431. \hl{line break} to occur within a program formatted by \.{WEAVE}; it is
  4432. ignored by \.{TANGLE}. Line breaks are chosen automatically by \TeX\
  4433. according to a scheme that works
  4434. \[most\] of the time, but sometimes you will prefer to force a line break
  4435. so that the program is segmented according to logical rather than visual
  4436. criteria.  Caution: \atcmd{/}~should be used only after statements or
  4437. clauses, not in the middle of an expression; use~\atcmd{|} in the middle of
  4438. expressions, in order to keep \.{WEAVE}'s parser happy.
  4439. \@|(optional line break in expression [code text])[C] ^^:\>{@"|}: ^^{line
  4440. break!optional}  ^^:insertion!optional line break: 
  4441. In code text, this control code specifies an \hl{optional line break} in
  4442. the midst of  an expression. For example, if you have a long condition
  4443. between \&{if} and \&{then}, or a long expression on the right-hand side of
  4444. an assignment statement, you can use~\atcmd{|} to specify breakpoints more
  4445. logical than the ones that \TeX\ might choose on visual grounds.
  4446. In \TeX\ text, this command is instead a literal vertical bar.  See the
  4447. discussion above.
  4448. \@\#(line break plus white space)[C] ^^:\>{@\PM}:^^{line!break!with white
  4449. space} ^^:insertion!line break!with white space:
  4450. This control code forces a \hl{line break}, like \atcmd{/}~does, and it also
  4451. causes a little extra white space to appear between the lines at this
  4452. break. 
  4453. \endKnuth
  4454. \[\Levy: 
  4455. \WEB\ automatically inserts this extra space between
  4456. functions, between external declarations and functions, and between
  4457. declarations and statements within a function.\] \[Furthermore, \It{this
  4458. command is essentially equivalent to a blank line in your source file},
  4459. unlike the original convention of \WEB. You should have to use this command
  4460. very rarely, since blank lines are so much easier and prettier looking in
  4461. the source file.  It is good practice to insert blank lines liberally in
  4462. your source file anyway for readability. For example, it usually looks best
  4463. if you set off things like \&{if} statements by blank lines.\]
  4464. \noindent Note that `\.{\PR}' is also the prefix for the preprocessor
  4465. commands. No confusion arises, however; \WEB\ interprets things like
  4466. \Endif\ as single units. 
  4467. \Knuth
  4468. \@+(cancel line break)[C] ^^:\>{@+}:^^{line!break!cancelling} 
  4469. ^^:insertion!line break!cancelling:
  4470. This control code cancels a 
  4471. line break that might otherwise be inserted by \.{WEAVE}.\ \bdots\ For
  4472. example, you might use this to force two statements to appear on the same
  4473. line, as in the \Fortran\ line 
  4474. {\codemode
  4475. a = b; @+ c = d
  4476. \noindent It is ignored by \.{TANGLE}.
  4477. \@;(pseudo-semicolon)[C] ^^:\>{@;}:^^:semicolon, pseudo-:
  4478. ^^:pseudo-!semicolon: 
  4479. This control code, \[sometimes 
  4480. called a \It{pseudo-semi}\], is treated like a semicolon, for formatting
  4481. purposes, except that it is invisible. You \[should\] use it, for example,
  4482. after a module name when the code text represented by that module name
  4483. \[represents a complete statement\], since \[in the absence of an explicit
  4484. format statement
  4485. \WEAVE\ thinks module names are just expressions\].
  4486. \endKnuth
  4487. Some examples of the use of pseudo-semis are in order. The principal use of
  4488. them is after module names in certain situations. Consider the following
  4489. situation: ^^<semicolon, pseudo->
  4490. {\codemode 
  4491. @ Here is an example of the use of pseudo-semicolons.
  4492. if(debug) @<Test@>@; // Use pseudo-semi here because @<Test@> ends with '\}'.
  4493. else @<Compute@>; // Use semi here because @<Compute@> does NOT end with ';'.
  4494. @<Test@>=
  4495. \stmt
  4496. @<Comp...@>= 
  4497. x = 1.0@; // Ends with a pseudo-semi so WEAVE will format it properly. 
  4498. \noindent The goal is to simultaneously fool \WEAVE\ into thinking that
  4499. you have written down a complete statement and to avoid introducing a
  4500. spurious semicolon where it doesn't belong. In particular, it would be
  4501. wrong (and would lead to a compiler error about an unmatched \&{else}) to
  4502. follow \.{@<Test@>} with a semicolon instead of a pseudo-semi, because the
  4503. definition of \.{@<Test@>} is already syntactically complete.
  4504. You may also need pseudo-semicolons to terminate macro definitions that are
  4505. not complete statements (but become one when they are terminated by a
  4506. semicolon in actual use). Some users feel annoyed at typing such
  4507. pseudo-semis; they feel they should be inserted automatically.
  4508. Unfortunately, they are not always necessary, and inserting extra ones will
  4509. typically at least insert an extra blank line in the output, possibly
  4510. worse. Nevertheless, the command-line option~`\.{-m;}' has been provided;
  4511. ^^:\>{-m;}: this will append a pseudo-semi to all \WEB\ macro definitions.
  4512. However, use of this option is not recommended.
  4513. \@e(pseudo-expression)[C] ^^:\>{@e}:^^:expression!pseudo-:
  4514. ^^:pseudo-!expression: 
  4515. The philosophy of the \It{pseudo-expression} is similar to that of 
  4516. the pseudo-semi. The pseudo-expression is treated like an expression (an
  4517. identifier is a simple expression) for formatting purposes, except that it
  4518. is invisible. It finds use in certain macro constructions that the syntax
  4519. analyzer would not otherwise recognize. For example, in~C the analyzer has
  4520. the rules $\hbox{\.*\It{expr}} \to \hbox{\It{expr}}$ and
  4521. $(\hbox{\It{expr}}) \to
  4522. \hbox{\It{expr}}$, but it doesn't understand the construction
  4523. `\.{(*)}', which occurs only very rarely in ordinary C~syntax (in certain
  4524. casts) but certainly might appear in unusual macro usage. The cure is to
  4525. use the pseudo-expression; \WEAVE\ will be happy if you say `\.{(*@e)}'.
  4526. \@:(pseudo-colon)[C] ^^:\>{@":}:^^:colon, pseudo-: ^^:pseudo-!colon:
  4527. The \It{pseudo-colon} is philosophically 
  4528. similar to both the pseudo-semicolon and the pseudo-expression: It's
  4529. treated just like a colon, except that it's invisible. It is useful in
  4530. formatting certain \&{case} constructions.  For example, consider
  4531. {\codemode
  4532. @<Special cases@>=
  4533. case 1:
  4534. case 2@: @;
  4535. \noindent The pseudo-colon is used so that one can later say ``\.{@<Special
  4536. cases@>:}'' when the module name is actually used.  The
  4537. pseudo-\It{semi}colon is used to terminate the module so that the syntax
  4538. analyzer can understand the entire construction as a statement and thus
  4539. format it properly.  
  4540. \Knuth
  4541. \parinsert{2}{6}{0.55}
  4542. ``{\ssbf WEAVE's built-in formatting method is fairly good, but it is
  4543. incapable of handling all possible cases...}''
  4544. The last \[eight\] control codes (namely~\atcmd{,}, \atcmd{/}, \atcmd{|},
  4545. \atcmd{\#}, \atcmd{+}, \atcmd{;}\[, \atcmd{e}, and \atcmd{:}\]) have no effect
  4546. on the program output by \.{TANGLE}; they merely help to improve the
  4547. readability of the \TeX-formatted \[code\] that is output by \.{WEAVE}, in
  4548. unusual circumstances. \.{WEAVE}'s built-in formatting method is fairly
  4549. good, but it is incapable of handling all possible cases, because it must
  4550. deal with fragments of text involving macros and module names; these
  4551. fragments do not necessarily obey the syntax
  4552. \[of the source languages themselves\].  Although \.{WEB} allows you to
  4553. override the automatic formatting, your best strategy is not to worry about
  4554. such things until you have seen what \.{WEAVE} produces automatically,
  4555. since you will probably need to make only a few corrections when you are
  4556. touching up your documentation.
  4557. Because of the rules by which every module is broken into three parts, the
  4558. control codes~\atcmd{d}, \atcmd{f}, \atcmd{l}, \atcmd{v}, and~\atcmd{a} are not
  4559. allowed to occur once the \[code\] part of a module has begun. Note that
  4560. \atcmd{m}~\It{is} allowed (unlike in the original \WEB\ design); it
  4561. signifies a deferred macro definition.
  4562. The \WEB\ control codes are summarized in Appendix~L.  ^^)control codes)
  4563. \dsection ADDITIONAL FEATURES and CAVEATS.[12.21]
  4564. Here we collect a miscellany of features, warnings, and suggestions.
  4565. \newfeature
  4566. \Feature Extended character sets. \[In Knuth's  original memo, this
  4567. remark was about extended character sets. See the 
  4568. documentation for \.{common.web} for more information.\] ^^{character set}
  4569. \Feature It's best to use ASCII characters. ^^[ASCII!using]
  4570. If you have an extended
  4571. character set, all of the characters listed 
  4572. in Appendix~C of {\sl The \TeX book\/} can be used in strings. But you
  4573. should stick to standard ASCII characters if you want to write programs
  4574. that will be useful to  all the poor souls out there who don't have
  4575. extended character sets.
  4576. \Feature Numerical constants. Hexadecimal, octal, and binary constants are
  4577. allowed in all 
  4578. ^^{constant!hexadecimal} ^^{constant!octal} ^^{constant!binary} languages,
  4579. generalizing the C-style format (which does not allow binary constants).
  4580. The syntax is \.{0x}$hhh$ for hexadecimal,
  4581. \.{0}$ooo$ for octal, or \.{0b}$iii$ for binary. Here $hhh$~stands for a
  4582. sequence of hexadecimal digits (0--9 and $A$--$F$), $ooo$~stands for a
  4583. sequence of octal digits (0--7), and $iii$~stands for a sequence of binary
  4584. digits (0 or~1). Of course, C~already recognizes hexadecimal and octal
  4585. constants, so for~C these are just passed through to the output unchanged.
  4586. In the other cases, the constants are converted (during tokenization in
  4587. phase one) to the appropriate integer. For example, in \Ratfor\ or
  4588. \Fortran\ each of
  4589. \.{0xF}, \.{017}, and \.{0b1111} is replaced by~15.
  4590. \Feature Special assignment and increment operators. In \Fortran\ and
  4591. \Ratfor,  the post-increment operators~`\.{++}' and `\.{--}'
  4592. ^^:operators!post-increment: ^^:\>{++}: ^^:\>{--}:
  4593. and the compound assignment operators
  4594. ^^:operators!compound assignment: ^^:\>{+=}: ^^:\>{-=}: ^^:\>{*=}: ^^:\>{/=}:
  4595. `\.{+=}', `\.{-=}', `\.{*=}', and~`\.{/=}' are allowed in
  4596. restricted contexts---namely, in simple assignment statements. These
  4597. operators translate as follows, where $x$~is anything allowed on the
  4598. left-hand side of an equals sign---for example, a subscripted expression:
  4599. {\codemode
  4600. \Tab x++; // -> `x = x + 1;'
  4601. \Tab x--; // -> `x = x - 1;'
  4602. \Tab x += expr; // -> `x = x + (expr);'
  4603. \Tab x -= expr; // -> `x = x - (expr);'
  4604. \Tab x *= expr; // -> `x = x*(expr);'
  4605. \Tab x /= expr; // -> `x = x/(expr);'
  4606. \noindent They are very useful at increasing the readability of your code.
  4607. They can also be used in the \Ratfor\ \&{for} statement. For example,
  4608. {\codemode
  4609. for(i++; i<100; i*= 5)
  4610. \noindent They cannot, however, be used in ways such as `\.{a(k++) =
  4611. b(i++);}', even though the analogous construction in~C is both legitimate
  4612. and often highly valuable. 
  4613. Furthermore, one must say `\.{i++}', not `\.{++i}', even though these would be
  4614. identical in~C when used stand-alone.  If one does not want these
  4615. constructions to be recognized, he may turn them off by the command-line
  4616. option~`\.{-+}'. ^^:\>{-+}:
  4617. \Feature Strings. ^^[strings]
  4618. Strings are delimited by single quotes (\Fortran), double quotes (C and
  4619. \Ratfor), or (in the case of certain built-in functions), by parentheses.
  4620. In order to continue quoted strings to another line,
  4621. ^^[strings!continuing]
  4622. all lines but the last
  4623. must end with a backslash (just as one would define a lengthy \C~macro).
  4624. Parenthesized strings should not be explicitly continued, unless the
  4625. command-line option `\.{-(}' is used. ^^:\>{-(}:
  4626. By default, the continuation of the string begins in column~1 of the next
  4627. line.  \Fortran--90 introduces a different convention, in which the
  4628. continuation of the string may begin in an arbitrary column, but \It{must}
  4629. be preceded by the same continuation character (an ampersand in
  4630. \Fortran--90) that was used at the end of the previous line.  This is
  4631. neither required nor allowed in \FWEB's default continuation mode.
  4632. However, if the \Fortran--90 convention is desired, it may be turned on by
  4633. the command-line option~`\.{-\\}'.
  4634. ^^:\>{-\BS}:
  4635. When turned on,
  4636. it operates for all languages, not just \Fortran--90.  As an example, the
  4637. following two lines of code are equivalent, both dealing with the string
  4638. \.{"12345"}. 
  4639. {\codemode
  4640. @n9[-n&]
  4641. @ The global language is Fortran--90, with free-form syntax.  
  4642. FWEB's default continuation convention is used.
  4643. x = "123&
  4644. // Now tell \\FWEB\\\space to use Fortran--90's continuation convention.
  4645. @n9[-n& -\\]
  4646. x = "123&
  4647. \Tab &45"
  4648. \Feature Breaking long strings. ^^[strings!breaking] ^^:strings!long:
  4649. \FWEAVE\ will break very long strings if necessary after embedded
  4650. commas, or after every so many characters. When it does so, it inserts a
  4651. backslash; this generally causes no confusion.
  4652. \Feature Breaking \TeX\ output lines. The \TeX\ file output by \.{WEAVE} is
  4653. broken into lines having, by default, at most 80 characters each. The
  4654. algorithm that 
  4655. does this line breaking ^^{line!breaking}
  4656. is unaware of \TeX's convention about comments following `\.\%' signs on a
  4657. line. When 
  4658. \TeX\ text is being copied, the existing line breaks are copied as well,
  4659. so there is no problem with `\.\%' signs unless the original \.{WEB} file
  4660. contains a line more than eighty characters long or a line with \[code\]
  4661. text in \pb\ that expands to more than eighty characters long.  (You may
  4662. not be likely to create such lines yourself, but certain processors that
  4663. create \WEB\ code automatically have been known to generate such long
  4664. lines.)  Such lines should not have `\.\%' signs.  If you run into trouble
  4665. here, you might try increasing the length of the output line by using the
  4666. command-line option ``\.{-yll$nn$}'', where $nn < 255$. ^^{output!file!line
  4667. length} 
  4668. \Feature Comments. In all languages, the preferred commenting style is that
  4669. of~C or 
  4670. \Cpp: \.{/*...*/} can be extended across newlines; \.{//...} is terminated
  4671. by a newline.
  4672. ^^[commenting style] ^^[comments]
  4673. In principle, these can be placed anywhere; however,
  4674. see suggestion~a) in the following item.  Note that standard \Fortran\ uses the
  4675. `\.{//}'~operator for concatenation.  Therefore, in \FWEB\ the short
  4676. comment is not recognized unless the one of the command-line
  4677. options~`\.{-n/}' (\Fortran), `\.{-r/}' (\Ratfor), or~`\.{-/}' (both \Fortran\
  4678. and \Ratfor) is used. ^^{\>{-n/}} ^^{\>{-r/}} ^^{\>{-/}}
  4679. To allow both ^{concatenation} and short comments, ^^{comment!short}
  4680. the operator~`\.{\\/}' ^^{\CS{/}}
  4681. has been introduced as an alternative symbol for
  4682. concatenation.  Also, \Fortran--90 introduces the exclamation point to begin
  4683. a single-line comment.  However, this conflicts with \FWEB's standard use
  4684. of the point for the logical \hbox{\.{NOT}}.  By default, therefore, \FWEB\
  4685. will not 
  4686. recognize the exclamation point as related to comments in \Fortran--90
  4687. unless one of the command-line options~`\.{-n!}', `\.{-r!}', or~`\.{-!}' is
  4688. used; ^^{\>{-n"!}} ^^{\>{-r"!}} ^^{\>{-"!}}
  4689. it will, however, always recognize the construction~`\.{!!}' ^^:\>{"!"!...}:
  4690. as the beginning of a short comment.  Thus, each of the following four lines
  4691. produces the same output for both \FTANGLE\ and \FWEAVE.
  4692. {\codemode
  4693. @n9[-n& -!]
  4694. x = y // z ! This is a comment.
  4695. x = y // z !! This is a comment.
  4696. @n9[-n& -n/]
  4697. x = y \\/ z // This is a comment.
  4698. x = y \\/ z !! This is a comment.
  4699. \Feature Translation of code text. \[Code\] text is translated by a
  4700. ``bottom up'' procedure that 
  4701. identifies each token as a ``part of speech'' and combines parts of speech
  4702. ^^{speech, parts of}
  4703. into larger and larger phrases as much as possible according to a special
  4704. grammar that is explained in the documentation of \.{WEAVE}. It is easy to
  4705. learn the translation scheme for simple constructions like single
  4706. identifiers and short expressions, just by looking at a few examples of
  4707. what \.{WEAVE} does (see the following paragraph), but the general
  4708. mechanism is somewhat complex because 
  4709. it must handle much more than \[code\] itself. Furthermore the output
  4710. contains embedded codes that cause \TeX\ to indent and break lines as
  4711. necessary, depending on the fonts used and the desired page width. For
  4712. best results it is wise to adhere to the following restrictions:
  4713. \yskip\itemitem{a)}Comments in \[code\] text should appear only after
  4714. statements or clauses; i.e., after semicolons, after reserved words like
  4715. \&{then} and \&{do}, or before reserved words like \&{end} and \&{else}.
  4716. \bdots
  4717. \itemitem{b)}Don't enclose long \[code\] texts in \pb, since the
  4718. indentation and line breaking codes are omitted when the \pb\ text is
  4719. translated from \[code\] to \TeX. Stick to simple expressions or
  4720. statements.
  4721. One can watch the translation in action by using the option~`\.{-2}' ^^:\>{-2}:
  4722. on \FWEAVE's command line. 
  4723. This will send to the terminal a detailed list of the actions \FWEAVE\
  4724. takes while combining parts of speech into phrases.  For example, the
  4725. simple C~program
  4726. {\codemode
  4727. main()
  4728. x = y;
  4729. \noindent will produce output something like the following:
  4730. {\codemode
  4731. Tracing after {l.} 8 (language = C):
  4732.   121: *expr +expr+ +\{+ expr... =="\\\{" "\\\\\{x\}"
  4733.     5: *+expr+ +\{+ expr...  =="\\\{" "\\\\\{x\}"
  4734.     1: *+fn_decl+ +\{+ expr +binop+...  =="\\\\\{x\}" "="
  4735.     3: *+fn_decl+ +\{+ +expr+ ;...  =="\\\\\{x\}" ";"
  4736.     6:  +fn_decl+*+\{+ +stmt+ +\}+ -ignore-  =="\\\}" "[force]"
  4737.   131: *+fn_decl+ -stmt+ -ignore-  \\"[force]$\{\}[[5]]$[force]$\{\}[[15]]
  4738. $[force]$\{\}[[10]]" "[force]"
  4739.    71: *+function- -ignore-  =="\\\\\{main\}" "[force]"
  4740.     0: *+function-  =="\\254" "\\\\\{main\}"
  4741. \noindent Each line begins with the number of the rule that was just
  4742. executed.  For example, rule~121 recognizes the combination~`\.{()}' as an
  4743. expression, and rule~71 recognizes that a function declaration
  4744. (`\.{main()}') followed by a complete statement (`\.{\{\dots\}}') is a
  4745. function.   The asterisk indicates the starting point for the next search
  4746. for a matching rule.  The leading and trailing plus and minus signs
  4747. indicate whether that particular part of speech begins or ends with math
  4748. mode (plus) or ordinary text mode (minus).  The last two quoted expressions
  4749. on a line 
  4750. are strings whose contents are the current translations of the last two
  4751. explicit parts of speech shown on the line.  (Some of the details of the
  4752. printed expressions are really intended for the developer of \FWEB\ and
  4753. need not be explained here.)  If all goes well, the last
  4754. line will 
  4755. consist of a single part of speech such as \\{function}; however, if there
  4756. is a rule missing or incorrect or if the source code syntax is invalid, the
  4757. final line may consist of a multitude 
  4758. of unreduced parts of speech.  Option~`\.{-1}' ^^:\>{-1}:
  4759. will print only such
  4760. unreduced scraps.  Such debugging can be turned on selectively by the
  4761. commands~\atcmd{1} or~\atcmd{2}, and turned off again by~\atcmd{0}.  
  4762. ^^:\>{@0}: ^^:\>{@1}: ^^:\>{@2}:
  4763. (The \atcmd{0}~should be placed in a  section separate from the other
  4764. debugging commands.) 
  4765. \Feature Code within vertical bars. ^^{\>{"|..."|}}
  4766. Comments \[and \WEB\ macro definitions\] are not
  4767. permitted in \pb\ text. After a `\.|'~signals the change from \TeX\ text to
  4768. \[code\] text, the next~`\.|' that is 
  4769. not part of a string or control text ends the \[code\] text.  Thus, you can
  4770. say ``\.{|@c x || y|}'' but not ``\.{|@c x | y|}''.  To handle the intent of
  4771. the last example, you may say ``\.{|@c x ||| y|}''. ^^:\>{"|"|"|}:
  4772. \Feature Braces in comments. ^^{braces!nested}
  4773. A comment must have properly nested occurrences of left and right
  4774. braces, otherwise \.{WEAVE} \[will try to balance the braces to keep \TeX\
  4775. from fouling up too much.  Unfortunately, the scanning mechanism that is
  4776. used here is optimized for speed, not perfection, so \WEAVE\ will complain
  4777. about the legitimate construction ``\.{/* ...\$\\\{\$... */}'', for
  4778. example.  You may need to introduce \TeX\ macros to avoid such warnings.\]
  4779. \comment
  4780. \parinsert{1}{3}{0.65}
  4781. ``Reserved words ... must appear entirely in lowercase letters in the
  4782. {\ssbf WEB} file.''
  4783. \endcomment
  4784. \Feature Reserved words. Reserved words of \[the individual languages, such
  4785. as \&{int} or 
  4786. \&{double precision}\]  must appear
  4787. entirely in lowercase letters in the \.{WEB} file; otherwise their special
  4788. nature will not be recognized by \.{WEAVE}.
  4789. ^^{identifiers!reserved}
  4790. You could, for example, have a macro named
  4791. \\{DIMENSION} and it would not be confused with \[\Fortran's\]
  4792. \&{dimension}. \bdots 
  4793. \endKnuth
  4794. \Feature \Fortran\ keywords. ^^{keywords!Fortran:\FORTRAN}
  4795. However, \Fortran\ also has another class of words, namely keywords such as
  4796. \.{BLOCKSIZE} or~`\.{ERR} that are used only inside I/O~statements. In
  4797. \Fortran\ and \Ratfor, the upper-case versions of these words are treated
  4798. as reserved and will be formatted in a special way that makes the
  4799. I/O~statements look appealing. 
  4800. \Knuth
  4801. \Feature Formatting identifiers. ^^[formatting] ^^{\>{@f}}
  4802. The \.{@f}~feature allows you to define one identifier to act like another,
  4803. and these format definitions are carried out sequentially\bdots. However,
  4804. a given identifier has only one printed format 
  4805. throughout the entire document (and this format will even be used before
  4806. the~\.{@f} that defines it). The reason is that \.{WEAVE} operates in two
  4807. passes; it processes~\.{@f}'s and cross-references on the first pass and
  4808. does the output on the second. \[(Note that in~C one has the possibility of
  4809. defining additional types via the \&{typedef} command. ^^{\<{typedef}}
  4810. This essentially acts like an implicit~\atcmd{f}.)\] 
  4811. \endKnuth
  4812. \Feature Formatting module names. In fact, as we have already stated, one
  4813. can also format a \It{module name}.
  4814. ^^{module!name!formatting}
  4815. By default, module names are interpreted as
  4816. expressions, but this is not always what is desired.  For example, one can
  4817. {\codemode
  4818. @f @<Common blocks@> common
  4819. \noindent and the parser will understand the use of \.{@<Com...@>} as a
  4820. type specification. Only the first slot of~\.{@f} is allowed to be a
  4821. module name; the second slot must always contain an identifier.
  4822. \Knuth
  4823. \Feature New reserved words. You may want some \.{@f}~formatting that
  4824. doesn't correspond to any 
  4825. existing reserved word. In that case, \.{WEAVE} could be extended in a
  4826. fairly obvious way to include new ``reserved words'' ^^{reserved words!new}
  4827. in its vocabulary.
  4828. \[For example, \WEAVE\ has already been taught to understand the identifier
  4829. \IF{Real} as an intrinsic function in Fortran. Note that a way of teaching
  4830. \WEAVE\ your own formats without recompiling is to include via~\.{@i} a
  4831. file including those format commands.\]
  4832. \endKnuth
  4833. \Feature Special array formatting. ^^[array!formatting]
  4834. Both \Fortran\ and~C have a somewhat vanilla-flavored syntax for array
  4835. elements---e.g., \.{f(i,j)} or \.{f[i][j]}.  In some physics applications
  4836. certain indices are preferred---e.g., they might be covariant or
  4837. contravariant----and it is useful to see this explicitly in the woven
  4838. output.  Also, some users are annoyed (with good reason) by the dual use of
  4839. parentheses in \Fortran\ to denote both function calls and array elements;
  4840. they prefer to see something like \.{f[i,j]} for a \Fortran\ array element.
  4841. Several features are available to help in this regard.
  4842. Usually the parentheses (\Fortran) or brackets (C) denoting array elements
  4843. are just passed through to the output by both \FTANGLE\ and \FWEAVE.
  4844. However, when the `\.{-W[}'~option is used, \FWEAVE\ inserts a special call
  4845. to the \TeX\ macro \.{\\WXA} ^^{\CS{WXA}}, with the array elements as
  4846. arguments.  By redefining the behavior of~\.{\\WXA}, a variety of special
  4847. effects can be achieved.  To be more precise, one shouldn't generally
  4848. modify the definition of~\.{\\WXA} itself, which is rather complicated;
  4849. rather, one should redefine \.{\\WARRAY}, ^^{\CS{WARRAY}}
  4850. which is called by~\.{\\WXA}.  See the following example.
  4851. Redefining \.{\\WARRAY} affects all array references.  
  4852. An even more general possibility is to use the \atcmd{W}~command ^^{\>{@W}}
  4853. to overload specific identifiers in different ways.  See the description
  4854. of~\atcmd{W} and the following example.
  4855. \HRULE
  4856. \typeset{demo4}
  4857. \HRULE
  4858. \Feature Forward references to identifiers.  ^^[forward references]
  4859. ^^[references!forward] ^^[subscripts, module number] 
  4860. We have learned that \FWEAVE\
  4861. makes two passes through the source file in order to handle forward
  4862. references to module names---i.e., the situation in which a module name is
  4863. used before it is defined.  It is desirable to extend this feature to
  4864. various identifiers such as function names and macros.  The convention is
  4865. to automatically \It{subscript} such identifiers with the number of the
  4866. module in which 
  4867. they are defined.  (The format can be changed by refining the \.{fwebmac}
  4868. macro~\.{\\WIN}; see below.) If the identifier has been defined in the
  4869. current section, then the numerical subscript is replaced by a small bullet.
  4870. ^^[functions!and forward referencing]
  4871. Implementing such a mechanism poses a difficult problem in general.  For
  4872. example,  function names are processed by \FWEAVE's syntax parser during
  4873. phase~2, so unless some special action is taken only function references
  4874. occurring \It{after} the  definition will be subscripted---in other words,
  4875. forward referencing would not work.  The most straightforward
  4876. way of solving this problem would be to make two passes through the
  4877. parser; however, this has been rejected as being too slow.  Nevertheless,
  4878. some partial solutions can be given.
  4879. First, one can force 
  4880. \FWEAVE\ to understand that an identifier is a function name by prefacing
  4881. it with the command~\atcmd{[}.  ^^:\>{@[}:
  4882. This command is executed during phase~1; it marks the name as being defined
  4883. in the current module.  Actually, it marks the first identifier it can find
  4884. that is 
  4885. not already known to be a reserved word, so the~\atcmd{[} may occur at the
  4886. very beginning of a function declaration.  This allows a further
  4887. convenience.  By default, the command~\atcmd{a} is equivalent to~`\atcmd{A@[}',
  4888. where \atcmd{A}~begins the unnamed module but does nothing else.  (Previously
  4889. in this manual, we have used~\atcmd{a} to begin the unnamed module; we now see
  4890. that that was a little white lie.)  Thus, the following three function
  4891. definitions are completely equivalent:
  4892. {\codemode
  4893. @ Explicitly mark the function name.
  4894. void @[f()
  4895. @ Explicitly mark the entire function name.
  4896. void f()
  4897. @ Rely on~`\.{@a}' to issue an implicit~`\.{@[}'.
  4898. void f()
  4899. \noindent Since the marks are executed during phase~1, forward referencing
  4900. is not a problem.
  4901. Thus, in the following code the references to functions~\\f and~\\g in
  4902. module~1 will be properly subscripted in the woven output.
  4903. {\codemode
  4904. @ An example of a function with forward referencing.
  4905. main()
  4906. @ Forward references to functions declared in the unnamed module are
  4907. handled with ease.
  4908. void f()
  4909. @ For named modules, one must mark explicitly if that is appropriate.
  4910. @<Special functions@>=@[
  4911. void g()
  4912. \noindent Note that at present section names do \It{not} automatically
  4913. issue an \atcmd{[}~command, so we had to insert one explicitly in the above
  4914. example.  This restriction may be removed in future releases.
  4915. Macro references can also be subscripted.
  4916. The commands~\atcmd{d} and~\atcmd{m} ^^{\>{@d}} ^^{\>{@m}}
  4917. issue implicit~\atcmd{[}s by default, so
  4918. you should have to do nothing explicitly to have macro references properly
  4919. identified.  If you never want a particular macro reference to be subscripted,
  4920. use the upper-case commands~\atcmd{D} or~\atcmd{M}. ^^:\={@d}{@D}: ^^:\={@m}{@M}:
  4921. In C-like languages additional types can be created via the \&{typedef}
  4922. command. ^^{\<{typedef}}
  4923. In the original \CWEB\ design, \&{typedef}s were processed during phase~2,
  4924. so there was again a problem with forward referencing.  The implicit~\atcmd{[}
  4925. command now issued by~\atcmd{a} aggravates the difficulty, as seen in the
  4926. following example:
  4927. {\codemode
  4928. @<Typedefs@>@;
  4929. @ The user-defined type |MY_TYPE| isn't understood here yet when |typedef|s
  4930. are processed in phase~2.  
  4931. MY_TYPE f()
  4932. @<Typedefs@>=
  4933. typedef int MY_TYPE;
  4934. \noindent Not only is the \&{typedef} name \&{MY\_TYPE} not understood when
  4935. it is discussed in the text, the implicit~\atcmd{[} issued by~\atcmd{a}
  4936. will incorrectly mark~\\{MY\_TYPE} instead of~\|f as a function defined in
  4937. the current module. Therefore, \&{typedef}s are now partly processed during
  4938. phase~1 to the extent that the identifier being \&{typedef}ed is now marked
  4939. as a reserved word.  Since the subscripting of identifiers is done during
  4940. the output in phase~2, the above example will now work correctly.
  4941. Here is a typeset illustration that contains forward references to function
  4942. names, macro references, and \&{typedef}s:
  4943. \HRULE
  4944. \typeset{demo3}
  4945. \HRULE
  4946. When many macro references and/or \&{typedef} statements are in use, one
  4947. may in some cases actually be annoyed by the clutter of subscripts.
  4948. Several mechanisms are provided to selectively turn on or off the subscripts.
  4949. First, all subscripts can be turned off from the command line by the
  4950. option~`\.{-f}'.  ^^:\>{-f}:
  4951. Second, style file entries (see section on ``Advanced Features'' below)
  4952. serve as switches to enable or disable 
  4953. subscripting for certain types of identifiers, according to the following
  4954. table: 
  4955. $$\vbox{\halign{\.{#}\hfil&\ ---\ #\hfil\cr
  4956. mark\_defined.generic\_name&Something explicitly marked by~\atcmd{[}. 
  4957. [$\WINo00$]\cr 
  4958. mark\_defined.fcn\_name&Function names.  [$\WINo11$]\cr
  4959. mark\_defined.WEB\_macro&\WEB\ macro (\.{@m}). [$\WINo22$]\cr
  4960. mark\_defined.outer\_macro&Outer macro (\.{@d}). [$\WINo33$]\cr
  4961. mark\_defined.exp\_type&Something explicitly marked by~\.{@\`}. 
  4962. [$\WINo44$]\cr
  4963. mark\_defined.typedef\_name&A \&{typedef}-like statement in C-like
  4964. languages. [$\WINo55$]\cr 
  4965. By default, \.{mark\_defined.generic\_name} and
  4966. \.{mark\_defined.exp\_type} are set to~1 (on); the others are set to~0
  4967. (off).  
  4968. Each of the above types of identifiers has a number, indicated in brackets.
  4969. This number is the first argument to the subscripting macro~\.{\\WIN}; 
  4970. ^^{\CS{WIN}}
  4971. the second argument is the number of the module in which the identifier was
  4972. defined.  Thus, if the function~\\{fcn} was defined in module~38, the
  4973. output \.{tex} file produced by \FWEAVE\ will contain the phrase
  4974. ``\.{\\\\\{fcn\}\\WIN1\{38\}}''.  The identifier number is used as an
  4975. argument to an \.{\\ifcase} statement, so the output format can be
  4976. different for different types of identifiers and can be controlled by the
  4977. user.  The default \.{fwebmac} macro~\.{\\WIN} subscripts all kinds of
  4978. identifiers with a bullet if they were defined in the current module.
  4979. Otherwise, the module number subscripts are typeset in the same style as
  4980. the bracketed numbers in the above table.  You may wish to experiment to
  4981. find an output format that is more informative or pleasing to your eye.
  4982. \Feature Spacing and macros. ^^[spacing]
  4983. Macros place unusual demands on \WEAVE. For example, suppose one defined
  4984. {\codemode
  4985. @m PLUS +
  4986. \noindent then attempted to use that macro in the expression ``\.{x\ PLUS\
  4987. y}''. This would tangle correctly and do what you want, but \WEAVE's output
  4988. would look like ``\|x\\{PLUS}\|y'', whereas what you really would like is
  4989. \hbox{``\|x\ \\{PLUS}\ \|y''}. This occurs because \WEAVE\ treats all normal
  4990. identifiers as expressions, and its rules tell it to simply concatenate
  4991. expressions (with no intervening white space). To help in situations like
  4992. this, \FWEAVE\ has a few extra 
  4993. reserved words that invoke special rules that insert extra spaces. These
  4994. words are \\{\$\_BINOP\_}, \\{\$\_COMMA\_},
  4995. \\{\$\_EXPR}, \\{\$\_EXPR\_}, \\{\$EXPR\_}, and \\{\$UNOP\_}. 
  4996. ^^:\>{\dollar\UL BINOP\UL}: ^^:\>{\dollar\UL COMMA\UL}: ^^:\>{\dollar UNOP\UL}:
  4997. ^^:\>{\dollar\UL EXPR}: ^^:\>{\dollar EXPR\UL}: ^^:\>{\dollar\UL EXPR\UL}: 
  4998. The underscores show where spaces will be inserted. You can format your unusual
  4999. macros to these words, as in
  5000. {\codemode
  5001. @f PLUS $_BINOP_
  5002. \noindent and your macro will then be treated as the proper part of
  5003. speech---either a binary operator, a comma, an expression, or a unary operator.
  5004. \Feature M4 built-in commands. ^^[built-in!\>{m4}] ^^{\>{m4}}
  5005. By default, \Fortran\ and \Ratfor\ do \It{not} understand the special
  5006. \.{m4}~preprocessor built-in 
  5007. commands: \undertext{\&{changequote}}, \&{define}, \&{divert},
  5008. \&{divnum}, \&{dnl}, \&{dumpdef}, \&{errprint}, \&{ifdef},
  5009. \undertext{\&{ifelse}}, \undertext{\&{include}}, \&{incr},
  5010. \undertext{\&{index}}, \undertext{\&{len}}, \undertext{\&{maketemp}},
  5011. \undertext{\&{sinclude}}, \undertext{\&{substr}}, \undertext{\&{syscmd}},
  5012. \undertext{\&{translit}}, and \&{undivert}. To make them understand \.{m4},
  5013. use the command-line option~`\.{-m4}'.
  5014. ^^:\>{-m4}:
  5015. Because these commands are
  5016. essentially macros, which need not obey the \Fortran\ syntax, \WEAVE\ has a
  5017. very difficult time formatting arbitrary \.{m4} constructions. To help
  5018. \WEAVE\ out, the underlined commands in the above list 
  5019. have their arguments interpreted as
  5020. strings (delimited by balanced parentheses), and \WEAVE\ will format them
  5021. as such, in typewriter type. These strings are treated just
  5022. like other strings, except that
  5023. if they don't end on the same line, they don't have to be
  5024. continued by a backslash. (However, you have the option of changing the
  5025. default. For parenthesized strings only, if you use the command-line
  5026. option~`\.{-(}', then those strings must be continued by backslashes.)
  5027. Similar considerations about string arguments apply to the \FWEB\ built-in
  5028. commands \undertext{\&{\_COMMENT}}, \undertext{\&{\_ERROR}},
  5029. \undertext{\&{\_IF}}, \undertext{\&{\_IFELSE}}, and
  5030. \undertext{\&{\_LEN}}. 
  5031. \Knuth
  5032. \Feature More general spacing. ^^[spacing]
  5033. Sometimes it is desirable to insert spacing into  code that is
  5034. more general than the thin space provided by~\atcmd{,}. The \.{@t}~feature
  5035. ^^{\>{@t}}
  5036. can be used for this purpose; e.g., \atcmd{t\\hskip 1in@>} will
  5037. leave one inch of blank space. Furthermore, \atcmd{t\\4@>} can be
  5038. used to backspace by one unit of indentation, since the control sequence
  5039. \.{\\4} is defined in \.{webmac} to be such a backspace. \bdots
  5040. \Feature Change file. ^^[file!change] ^^[change file]
  5041. \.{WEAVE} and \.{TANGLE} are designed to work with two input files,
  5042. called \\{web\_file} and \\{change\_file}, where \\{change\_file} contains
  5043. data that overrides selected portions of \\{web\_file}. The resulting merged
  5044. text is actually what has been called the \.{WEB} file elsewhere in this
  5045. report.
  5046. Here's how it works: The change file consists of zero or more ``changes,''
  5047. where a change has the form `\.{@x}$\langle$old lines$\rangle$\.{@y}$\langle$%
  5048. new lines$\rangle$\.{@z}'. 
  5049. ^^:\>{@x}:^^:\>{@y}:^^:\>{@z}:
  5050. The special control codes \.{@x}, \.{@y}, \.{@z} must appear at the
  5051. beginning of a line; the remainder of such a line is ignored.
  5052. The $\langle$old lines$\rangle$ represent material that exactly matches
  5053. consecutive lines of the \\{web\_file}; the $\langle$new lines$\rangle$
  5054. represent zero or more lines that are supposed to replace the old. Whenever
  5055. the first ``old line'' of a change is found to match a line in the
  5056. \\{web\_file}, all the other lines in that change must match too.
  5057. Between changes, before the first change, and after the last change,
  5058. the change file can have any number of lines that do not begin
  5059. with~\atcmd{x}, \atcmd{y}, or~\atcmd{z}. Such lines are bypassed and not used
  5060. for  
  5061. matching purposes, except for the following special codes.
  5062. \endKnuth
  5063. In addition to \atcmd{x}, \atcmd{y}, and~\atcmd{z}, the language commands
  5064. \atcmd{c}, \atcmd{r}, \atcmd{n}, and~\atcmd{L\It{l}} are also allowed in the
  5065. change file, as are the commands \atcmd{[} and \atcmd{]}.
  5066. ^^{\>{@c}} ^^{\>{@r}} ^^{\>{@n}} ^^:\>{@[}: ^^:\>{@]}:
  5067. All these commands must begin in column~1. The command
  5068. \atcmd{[} means switch into code mode; 
  5069. ^^{code!mode} ^^{mode!code}
  5070. \atcmd{]} means switch out of code
  5071. mode. These latter commands are necessary only in \Fortran, but are crucial
  5072. there. Although modes switch back and forth automatically between free-form
  5073. and column syntax as the input driver reads sequentially through the \It{input}
  5074. file, that can't happen automatically for the \It{change} file, which consists
  5075. of isolated fragments of text that could match any line of the input file,
  5076. in either \TeX\ mode or code mode.  If you do not help out the change file,
  5077. the input driver will probably not interpret the syntax of the change file
  5078. in the same way as it does the source file, and lines that look identical
  5079. in the source files nevertheless won't match.
  5080. For example, if a \Fortran--77 source file contains the line
  5081. {\codemode
  5082. \Tab call open('datafile')
  5083. \noindent the following change file will replace that line with two new lines:
  5084. {\codemode
  5085. \Tab call open('datafile')
  5086. /* Here are the replacement lines: */
  5087. \Tab call open('newdatafile')
  5088. \Knuth
  5089. This dual-input feature is useful when working with a master \.{FWEB} file
  5090. that has been received from elsewhere (e.g., \.{FTANGLE.WEB} or
  5091. \.{FWEAVE.WEB}), when changes are desirable to customize the
  5092. program for your local computer system. You will be able to debug your
  5093. system-dependent changes without clobbering the master \.{web} file; and once
  5094. your changes are working, you will be able to incorporate them readily
  5095. into new releases of the master web file that you might receive from time
  5096. to time.
  5097. \endKnuth
  5098. You specify the name of the change file on the command line; 
  5099. ^^:file!change!name of:
  5100. it is the
  5101. second command-line argument that the parser can recognize as a file
  5102. name---i.e, that does not begin with a hyphen.  A default extension of
  5103. `\.{.ch}' is implied.  If you just say `\.{FTANGLE test}', you are talking
  5104. about the web file `\.{test.web}' with the null change file. If you
  5105. say `\.{FTANGLE test test}', you are talking about the web file
  5106. `\.{test.web}' and the change file `\.{test.ch}'. If you say `\.{FTANGLE
  5107. alpha.fweb beta.fch}', you are calling for the web file `\.{alpha.fweb}'
  5108. and the change file `\.{beta.fch}'. It is almost never necessary to deal
  5109. with nondefault file extensions.  (The range of default extensions can
  5110. be increased by entries in the style file.  See the following discussion of
  5111. the style file and of the command-line option~`\.{-e}'.)
  5112. \section INPUT.[13.4] ^^(input( ^^[driver!input]
  5113. It doesn't take much time attempting to fit the column-oriented \Fortran--77
  5114. syntax into the \WEB\ framework to realize the virtues of languages such
  5115. as~C, \Ratfor, or \Fortran--90 with free-form syntax. The present \FWEB\
  5116. design solves the problem of 
  5117. multiple, incompatible input syntaxes by introducing the concept of
  5118. \It{input drivers}. These are front ends that convert the incoming syntax
  5119. as quickly as possible  to a uniform syntax that the innards of \FWEB\
  5120. can understand.  Individual lines from the \WEB\ file are filtered through
  5121. the \It{input driver} appropriate to whatever language is in force at that
  5122. point. For~\C, that filter is essentially a unit operator; it presents to
  5123. \FWEAVE\ and \FTANGLE\ the same input line that it read in. At the other
  5124. extreme, however, for
  5125. \Fortran--77 the filter does much more work. Because of the possibility of
  5126. \It{continuation lines}, the filter must read ahead. If it finds a
  5127. continuation line, it concatenates it to the stuff already in the filter's
  5128. buffer. Finally, when it finds no more continuations, it \It{appends a
  5129. semicolon} to the logical line it has constructed, then presents this line
  5130. to the innards of \FWEAVE\ or \FTANGLE. The semicolon serves as the
  5131. end-of-statement delimiter, just as it does in~\C. Thus, the input line
  5132. presented to the processors has a standard form for all supported
  5133. languages, so it can be parsed in a standard way.
  5134. In fact, the \Fortran\ and \Ratfor\ drivers do even more things, especially
  5135. related to comments. These details will be described in the following
  5136. sections. Here, the point to remember is that your input file can pretty
  5137. well follow the conventions of whatever mode you're in at the moment: \C, \Cpp,
  5138. \Fortran, \TeX, or whatever.
  5139. \subsection \Fortran--77 input.^^[Fortran:\FORTRAN!input driver] 
  5140.     ^^[input!Fortran:\FORTRAN--77]
  5141. \It{It is recommended that you do not use bare \Fortran\ for new
  5142. codes; use \Ratfor\ instead.} Another option is to use the free-form mode
  5143. of \Fortran--90.
  5144. ^^[comment!Fortran:\FORTRAN]
  5145. Although the preferred commenting style is C-style, the \Fortran\ column-1
  5146. convention is retained for compatibility with existing code. These two
  5147. styles are fundamentally incompatible, and the \Fortran\ style is
  5148. definitely not recommended! Note that
  5149. trailing comments beginning with an exclamation point \It{will not work}!
  5150. \indent\.{x = y !This doesn't work in Fortran--77.}
  5151. \noindent This is a VAX extension that conflicts with the standard \WEB\
  5152. use of the exclamation point, as it is the input symbol for the logical
  5153. \hbox{\.{NOT}}. (See below.) If your 
  5154. source file already contains such comments, you must change them into
  5155. C-style ones. With the aid of a good editor, this can be done with just one
  5156. command repeated automatically.
  5157. Following the conventions of \Fortran--77, lines that begin with~'\.C',
  5158. '\.c', or~'\.*' are 
  5159. (short) comments (terminated by the end-of-line).  When the
  5160. option~`\.{-n/}' is in effect, these lines behave 
  5161. identically to ones beginning with~`\.{//}'.  Consecutive comments of the
  5162. same kind (long or short) are concatenated by the input driver.  Thus, the
  5163. construction 
  5164. {\codemode
  5165. /* A */ /* B */
  5166. \noindent will be typeset into the two lines
  5167. {\WP\6
  5168. \WC{ A B }\6
  5169. \Wc{C D E}\6
  5170. Since the input driver concatenates successive lines of the same type, very
  5171. long effective input lines can be created.  Sometimes the associated buffer
  5172. overflows and \FWEB\ terminates with an error message.  Since that buffer
  5173. is allocated dynamically, one can use the `\.{-y}'~option to increase its
  5174. size; the error message explains how.
  5175. A comment that appears on
  5176. the line immediately after a statement or continuation line will be
  5177. attached to the previous line as a trailing comment. Generally, this is not
  5178. what you want; a comment beginning in column~1 probably belongs with the
  5179. next statement. One solution is to insert a blank line before the comment.
  5180. This puts a blank line in your woven output. If you don't want that, omit
  5181. the blank line and preface the comment by~\atcmd{/}.
  5182. The commenting rules are such that both \FTANGLE\ and \FWEAVE\ will handle
  5183. ^[compiler directives] appropriately. Typically a compiler directive begins
  5184. with the character~'\.C' so it will be ignored by a compiler that doesn't
  5185. understand the directive. Thus if \.{cdir}~is a compiler directive, one can
  5186. say ^^<compiler directives>
  5187. {\codemode
  5188. \Tab x = y
  5189. cdir Text of the directive
  5190. \Tab (more code)
  5191. \noindent and the compiler directive will be executed. Note the important
  5192. blank line before the directive. If it were not there, the directive would
  5193. be treated as a trailing comment attached to the previous line of code.
  5194. (It is instructive to try this example with the blank line both present and
  5195. absent. With the blank line absent, you will find that the~'\.d'
  5196. of~\.{cdir} gets eaten. This occurs because of a quirk of the input driver
  5197. that will be fixed someday.)  However, for new codes a much better
  5198. solution for compiler 
  5199. directives is to use the \atcmd{?}~command; see the discussion in the
  5200. section on control codes.
  5201. \parinsert{2}{7}{0.55}
  5202. ``By default the semicolons are actually appended as {\bfit
  5203. pseudo-semicolons}, so they will be invisible on output.''
  5204. The \Fortran--77 input driver recognizes the end of a valid statement when the
  5205. next line is neither a continuation nor a comment. At this point, the input
  5206. driver performs a scan over everything it has collected so far and
  5207. concatenates any adjacent comments of the same type.  It then
  5208. \It{appends a semicolon} to the end of the compilable part of the statement
  5209. (i.e., just before the last comment), because the semicolon is used as a
  5210. universal statement terminator in the innards of \FWEAVE\ and \FTANGLE.
  5211. Logically, the semicolons should show up in the woven output, since they
  5212. are \FWEB's way of terminating statements.  However, this makes the
  5213. \Fortran\ output look a little strange, and, logic notwithstanding, people
  5214. have understandably found this annoying.  Therefore, by default the
  5215. semicolons are actually appended as
  5216. \It{pseudo-semicolons}, so they will be invisible on output.  To make the
  5217. semicolons 
  5218. visible, use the command-line option~`\.{-np}'.  \FTANGLE, of course, always
  5219. throws the semicolons away during its output phase, since they would not be
  5220. understood by the compiler.
  5221. If you think the \Fortran\ input driver isn't working the way it's supposed
  5222. to (for example, if it doesn't concatenate continuation lines properly),
  5223. you might want to look at the line-by-line output from the driver. You can
  5224. turn on this debugging feature with the command-line option `\.{-l}'. 
  5225. ^^:\>{-l}:
  5226. If this confirms that something is wrong, by all means report the bug. The
  5227. \Fortran\ driver is much too complicated for its own good!  (Often, bugs
  5228. show up in incorrect continuation lines.  These can often be circumvented
  5229. by using the \.{-\#}
  5230. ^^{\>{-\PM}}
  5231. option to remove the line- and module-number comments.)
  5232. If all goes well and \WEAVE\ is able to recognize a complete main program,
  5233. function, or subroutine, the body of that program unit is indented.
  5234. To be consistent, you should use the \&{program} statement for main
  5235. programs; otherwise, the indentation may appear strange. (You may
  5236. call this a bug, but it's really a design ``feature''.)
  5237. ^^[input!alternative operators for]
  5238. \Fortran\ contains such archaic constructions as `\.{.ne.}'. \WEB\ has two
  5239. ways of helping you to deal with these things. You are allowed more
  5240. flexibility in input, and \WEAVE\ substitutes prettier constructions such
  5241. as `$\neq$' as it typesets the documentation. (The exact form of the output
  5242. is controlled by a \TeX\ macro; study \.{fwebmac.web}. Thus, if you don't
  5243. like the way exponentiation is typeset, for example, you can easily change
  5244. it without recompiling \FWEB.) 
  5245. \input dots
  5246. A few restrictions or modifications of \Fortran's rules have been made in
  5247. the interest of 
  5248. simplicity. First, \FWEB\ recognizes identifiers in a slightly different
  5249. way than does \Fortran. As an extension compatible with \Ratfor\ and~\C,
  5250. identifiers may contain underscores and dollar
  5251. signs and may be of arbitrary length. (\FTANGLE\ can
  5252. translate these to garden-variety \Fortran\ identifiers; see the discussion
  5253. of the \.{-t}~option. ^^{\>{-t}}
  5254. On the other hand, as a restriction
  5255. there may not be any white space within identifiers.
  5256. (However, \FWEAVE\ will correctly understand \&{go to}, \&{else if}, 
  5257. \&{end if}, and \&{end do}.) 
  5258. Secondly, there are a few cases in \Fortran\ where the same identifier is
  5259. allowed to be used in two entirely different ways. Perhaps the most
  5260. prominent case is the identifier \.{real}, ^^{\<{real}}
  5261. which is used both as a type
  5262. specification and as an intrinsic function. \FWEAVE, not being as
  5263. intelligent as the \Fortran\ compiler, does not understand enough about the
  5264. syntax to properly distinguish these two uses; specifically, it understands
  5265. \.{real} only as a type specification. In cases such as this, one can often
  5266. make \FWEAVE\ happy by recalling that \FWEAVE's reserved words are all in
  5267. lower case, but that \Fortran\ is case-insensitive. Thus, \Fortran\ doesn't
  5268. care whether you type \.{real} or \.{Real}, but \FWEAVE\ will not confuse
  5269. \\{Real} with a type specifier. In fact, for this particular case \FWEAVE\
  5270. has been taught to understand that \\{Real} is an intrinsic function, so
  5271. what you will really get is
  5272. \&{real} and \IF{Real}.  
  5273. As a matter of good programming style,
  5274. you just shouldn't get into this situation if you can avoid it. Don't, for
  5275. example, use \\{Integer} as the name of a function, even though \Fortran\
  5276. allows that and \FWEAVE\ will treat it as an ordinary identifier.
  5277. Standard \Fortran--77 does not understand the unnumbered block \&{do}
  5278. construction, which is a VAX extension. \FTANGLE\ understands such
  5279. constructions, and can optionally 
  5280. convert them into standard numbered \&{do}s. See the description of the
  5281. command-line option `\.{-d}'. (This mode is slow, and is not recommended.
  5282. Use \Ratfor\ or \Fortran--90 instead.)
  5283. ^^:\>{-d}:
  5284. ^^{declarations!\<{common}}
  5285. An excellent application of named modules is to define things like \&{common}
  5286. declarations that you wish to insert at the beginning of every subroutine.
  5287. By using a named module, you can keep the code for the common declarations
  5288. in the same file as the rest of your code; a separate include file is
  5289. unnecessary. 
  5290. One of the annoying \Fortran\ constructs is the ``dot constant''---e.g.,
  5291. `\.{.false.}' or~`\.{.eq.}'.  ^^:constant!dot:
  5292. In some cases \FWEB\ gets confused by the
  5293. periods, which are used for other purposes as well.  For example, a VAX
  5294. extension uses periods to separate components of structures.  (\Fortran--90
  5295. uses~`\.{\%}' for this purpose.)  If you want, you can change the delimiters
  5296. of such dot constants via the style-file options \.{dot\_constant.begin}
  5297. and \.{dot\_constant.end}.
  5298. ^^{style file!vocabulary!\>{dot\UL constant.begin}} 
  5299. ^^{style file!vocabulary!\>{dot\UL constant.end}}
  5300. For example, if you say in \.{fweb.sty} ^^{\>{fweb.sty}}
  5301. {\codemode
  5302. dot_constant.begin '['
  5303. dot_constant.end ']'
  5304. \noindent then you can say in your code things like
  5305. ``\.{if(a[eq]b)\dots}''.  However, generally it is better to say
  5306. ``\.{if(a==b)\dots}''.  The command-line option~`\.{-.}' tells \FWEB\ to
  5307. not attempt to identify dot constants (even when the delimiters have been
  5308. changed as above).  Use this option if your compiler uses periods for
  5309. something else. 
  5310. \subsection \Fortran--90 input. ^^[input!Fortran--90:\FORTRAN--90]
  5311. \Fortran--90 permits two input syntax styles:  column format, as in
  5312. \Fortran--77, and free-form format.  The column format behaves as in
  5313. \Fortran--77; see the previous subsection.  The free-form format is a great
  5314. advance, and should be used for new code.  The following remarks pertain to
  5315. free-form input.
  5316. In free-form input, lines are continued by a character at the \It{end} of
  5317. the line instead of one in column~6 of the next line.  
  5318. The ^:continuation character: is selected by a command-line option, which also
  5319. serves to turn on the free-form input mode.  You may choose either
  5320. `\.{-n\&}' or~`\.{-n\\}', ^^{\>{-n\amp}} ^^{\>{-n\BS}}
  5321. allowing one to continue lines with either an
  5322. ampersand (\Fortran--90's rule) or a backslash (compatible with~C and other
  5323. \WEB\ conventions).  (If you select~`\.{-n\\}',
  5324. \FTANGLE\ will convert the backslash into an ampersand on output.)
  5325. For example, here is how to begin a \.{web} source code written with
  5326. free-form \Fortran--90:
  5327. {\codemode
  5328. @n9[-n& -n/]
  5329. @* INTRODUCTION.  The following code will be in free-form Fortran--90.
  5330. (It may take a lot of CPU time.)
  5331. program main
  5332. integer i
  5333.     0 // Illustration of line continuation.
  5334. iterate: do
  5335.     end do iterate
  5336. \subsection \Ratfor\ input. ^^[input!Ratfor:\RATFOR]
  5337. By default, the auto-semi mode is not used. In this case the
  5338. \Ratfor\ syntax is completely free-form and identical to that of~C.
  5339. In the auto-semi mode
  5340. ^^{mode!auto-semi}
  5341. the input driver will turn  the \Ratfor-style comment
  5342. (anything between~`\.{\#}' and the end-of-line) into a C-style comment.
  5343. ('\.{\#}'~characters embedded in comments will just be copied, and paste
  5344. tokens~(`\.{\#\#}') in \WEB\ macro definitions will be properly understood.)
  5345. As described earlier, in that mode it also
  5346. handles the \Ratfor\ style of obvious continuation, and supplies
  5347. semicolons in the appropriate places.
  5348. With the exception of remarks specific to \Fortran's
  5349. line-and-column-oriented syntax, all the other remarks about \Fortran\
  5350. apply to \Ratfor\ as well.
  5351. \subsection C and \Cpp\ input. ^^[input!C] ^^[input!C++]
  5352. This is the bare-bones driver; it does nothing but pass the free-form
  5353. syntax along to the innards of the processors. This driver is also used for
  5354. \Ratfor. 
  5355. Beginning with version~1.21, \&{typedef}ed variables ^^{\<{typedef}}
  5356. can be marked automatically with the number of the module in which they are
  5357. defined.  See the previous discussion of ``Forward References.''
  5358. One formatting annoyance is concerned with constructions of the form
  5359. {\codemode
  5360. typedef struct weird
  5361. \Tab \{
  5362. \Tab ...
  5363. \Tab \} weird;
  5364. \noindent The C~language permits this construction, in which \\{weird} is used
  5365. in two ways.  However, \WEAVE\ is not as clever as a compiler; it only
  5366. understands one interpretation of a variable, and will likely become slightly
  5367. confused by the above situation.  It's not really good programming practice
  5368. to use an identifier in more than one way anyway; replace the last
  5369. \\{weird} by \\{WEIRD}, or the first \\{weird} by \\{weird0}.
  5370. ^^)input)
  5371. \section COMMAND-LINE OPTIONS.[14.3] ^^(options!command-line(
  5372. ^^[command line!options] ^^[syntax rules!command line]
  5373. Various information of interest to \FWEAVE\ and/or \FTANGLE\ may be entered
  5374. from the command line. Command-line arguments are delimited by spaces; if
  5375. you need a space inside an argument itself, surround the argument with
  5376. quotes (single or double, depending on your operating system or shell).
  5377. Since the arguments are case-sensitive, remember that 
  5378. under VAX/VMS arguments are translated into lower case
  5379. unless they are protected by double quotes.  Under \Unix, certain characters
  5380. such as ``\.{\&|;<>()\{\}*?[]}'' may mean special things to the shell
  5381. ^^{shell, special characters for} and may need to be escaped with a
  5382. backslash or protected with quotes.  Thus, while under VMS a valid option
  5383. is `\.{->}', under \Unix\ you must say `\.{-'>'}' or~`\.{-\\>}'.  (Since this
  5384. is cumbersome to type, the synonym~`\.{-=}' has been provided.)
  5385. \parinsert{3}{4}{0.5}
  5386. ``Command-line arguments may appear in any order.''
  5387. Command-line arguments ^^[command line!arguments]
  5388. may appear in any order; they are processed from left to right.
  5389. If a command-line argument does not begin with a hyphen, it is understood
  5390. to be a file name.   The first file name found is the name of the \WEB\
  5391. source file; 
  5392. optionally, if a second file name is found, it is the name of the change file.
  5393. If the name (excluding a possible path)
  5394. contains a period, then it is processed exactly as specified.
  5395. Otherwise, \WEB\ supplies an extension. Precisely how this is done depends
  5396. on whether the `\.{-e}'~option is in effect.  If it is not in effect, then a
  5397. default extension is used:  ``\.{.web}'' for the \WEB\ file,
  5398. ``\.{.ch}''~for the change file.  If it is in effect, then  extensions 
  5399. taken  from the relevant style file entry (\.{ext.web} or \.{ext.change})
  5400. are applied in turn until one matches. A
  5401. lone hyphen~`\.-' is understood to stand for the special file \.{stdin}
  5402. ^^{\>{stdin}} 
  5403. (standard input),
  5404. which is usually the terminal.  Hyphenated options should have no space
  5405. between the option and its parameter, if one is required.
  5406. Thus, an example of a command line is
  5407. {\codemode 
  5408. fweave test test -wmy_macros
  5409. \noindent which means ``Weave the file \.{test.web} using the change file
  5410. \.{test.ch}; print `\.{\\input my\_macros}' at the beginning of
  5411. \.{test.tex}.''   It would be an error if \.{test.web} were missing.
  5412. However, if one had said in the style file ``\.{ext.web = "web\ wb"}'' and
  5413. used the `\.{-e}'~option, then in the absence of \.{test.web} the system
  5414. would attempt to open \.{test.wb}.  This same mechanism works for file
  5415. names specified on \.{@i}~lines (see the discussion of the control
  5416. code~\atcmd{i}, except that if the `\.{-e}'~option is not in effect there
  5417. are no default extensions.  The associated style-file entries are
  5418. \.{ext.hweb} for the included web file and \.{ext.hchange} for the
  5419. associated change file.
  5420. Certain command-line options can be negated by including an extra hyphen.
  5421. ^^[command line!options!negating]
  5422. For example,
  5423. {\codemode
  5424. fweave test --x
  5425. \noindent means ``Do the opposite of option `\.{-x}'.''  Since
  5426. `\.{-x}'~means suppress all cross-reference information, `\.{--x}'~means
  5427. ``\It{do} write all cross-reference information.''  
  5428. ^^{cross-references!printing} ^^{cross-references!suppressing}
  5429. This example is essentially pedagogical, 
  5430. since that information is normally written anyway by default.  The most common
  5431. reason to negate an option is when one wishes to override an option that
  5432. was set in the initialization file~\.{.fweb} (discussed below).  For
  5433. example, \.{.fweb}~might contain 
  5434. the command~`\.{+v}', which tells \FTANGLE\ to make all comments verbatim
  5435. and pass them along to the output file.  If you want to turn off those
  5436. comments for one particular run, say `\.{--v}'~on the command line.
  5437. \subsection Options to language commands. 
  5438. Whenever a language is changed via a control code such as~\atcmd{c}, that code
  5439. may be optionally followed by text, optionally enclosed in square brackets.
  5440. This was explained in the section on languages.  The optional text is
  5441. essentially parsed as though it were a command line; this affords a way
  5442. of selecting different parameters for each language.  For example, the
  5443. following are valid commands:
  5444. {\codemode
  5445. @c++ @% Select c++.
  5446. @r[-k*] @% Select Ratfor, and suppress comments about keyword expansions.
  5447. \noindent However, some options such as~\.{-x} are truly global and are not
  5448. reasonably changed in the midst of the \.{web} source.  Those global
  5449. commands that may \It{not}
  5450. be used inside brackets are marked in the following list with asterisks.
  5451. \subsection List of options.
  5452. Here are the options (brackets mean optional arguments; case is significant):
  5453. \clo{
  5454. -&^^:\>{-}: The file name ``\.{stdin}'', ^^{\>{stdin}}
  5455.  which signifies ``standard input''. ^^{input!standard}\cr
  5456. -0&^^:\>{-0}: Turn off \WEAVE's debugging output.  (The command~\atcmd{0}
  5457.  should be placed in a different module from~\atcmd{1} or~\atcmd{2}.)
  5458. ^^:debugging!turning off:\cr
  5459. -1&^^:\>{-1}: Turn on limited debugging for \FWEAVE. 
  5460.  ^^:debugging!turning on!limited:\cr
  5461. -2&^^:\>{-2}: Turn on full verbose debugging for \FWEAVE. ^^:debugging!turning
  5462.  on!verbose:\cr 
  5463. -A&^^:\={-a}{-A}: Turn on translations to \&{ASCII}.  (On \&{ASCII} machines,
  5464.  translations to the internal \&{ASCII} representation are redundant, so are
  5465.  turned off by default.  This flag is used for debugging.  On non-ASCII
  5466.  machines, the translations are done regardless of the setting of this
  5467.  flag.) ^^:ASCII!turning on translations to:\cr 
  5468. -b &^^{\>{-b}} Number \&{do} and \&{if}~blocks in woven \Fortran\ and \Ratfor\
  5469.     output.  This is helpful when the blocks are highly nested and/or long.
  5470.     The form of this numbering is defined by the \.{fwebmac}
  5471.     macro \.{\\Wblock}, which by default prints as `\hbox{\Wblock{99}}'.
  5472.     ^^:\CS{Wblock}: ^^{block numbers}\cr
  5473. \lstar -c&^^:\>{-c}: Set the global language to~\C. \It{(Will be overridden
  5474.     by a language command in limbo.)} ^^:language!global!C:\cr
  5475. -c++&^^:\>{-c++}: Set the global language to~\Cpp.
  5476.     ^^:language!global!\Cpp:\cr 
  5477. -D\It{[letters]}&^^:\={-d}{-D}: Display information about reserved words of the
  5478.     current (command-line) language (beginning with \It{letters} if
  5479.     present).   
  5480.     For example, to see all the reserved words of~C, say ``\.{ftangle
  5481.     -c -D}''.
  5482.     ^^:reserved words!displaying:\cr
  5483. -d\It{[nnnnn]}&^^:\>{-d}: In \Fortran--77, this tells \TANGLE\ to convert
  5484.     unnumbered `\&{do}\dots\&{enddo}' constructions to numbered ones of
  5485.     the form `\&{do} 
  5486.     {10000} \dots\ {10000} \&{continue}'. The constructions are numbered
  5487.     uniquely, without regard for subroutine boundaries. By default, the
  5488.     numbering starts with a large number such as~90000. If you wish to
  5489.     change 
  5490.     that starting number, say `-d\It{nnnnn}', where \It{nnnnn} is an
  5491.     integer 
  5492.     number sufficiently less than~99999. Any statement numbers that you use
  5493.     yourself should be less than that starting number.  (This feature
  5494.     is a kludge and is slow; use \Ratfor\ instead.)
  5495.     ^^:\<{do}!numbering:\cr
  5496. \vfill\Eject
  5497. \clo{
  5498. -E$c$&^^:\={-e}{-E}: Change the delimiter of a file-name extension from the
  5499.     default~'\..' to~'$c$'.  This option is included because on some
  5500.     (weird) systems the period is used as a directory delimiter.
  5501.     ^^:extensions!file-name!changing delimiter for:\cr
  5502. -e&^^:\>{-c}: Turn on automatic file-name completion.  ^^:file
  5503. name!automatic completion of:
  5504. If any file name contains a period, then it is assumed that this is the
  5505. complete name of the 
  5506. file to be opened.  If it does not contain a period, then trial names are 
  5507. constructed by appending in turn each extension from the relevant
  5508. style-file extension list:  one of \.{ext.web}, \.{ext.change},
  5509. \.{ext.hweb}, or  
  5510. \.{ext.hchange}.  The first trial name that matches a file in the user's
  5511. directory is opened.  For example, if one says in the style file
  5512. ``\.{ext.hweb = "hweb\ hw"}'' and uses an include line of the form ``\.{@i\
  5513. my\_includes}'', the system will search for the include files
  5514. \.{my\_includes.hweb} and \.{my\_includes.hw}, using the first one it
  5515. finds.\cr 
  5516. -f&^^:\>{-f}: Turn off the module reference subscripts for all identifiers.
  5517. ^^:module!references!turning off:\cr
  5518. \lstar -h&^^:\>{-h}: Get help from the command line. \It{(Not implemented
  5519.     yet; just refers the user elsewhere and quits.)} ^^:help!command
  5520.     line:\cr  
  5521. -i&^^:\>{-i}: This option is intended to help cut down on the volume 
  5522.     of woven output. It tells \FWEAVE\ to read include files named by the
  5523.     \atcmd{I} command, but to not print their contents. (Include files
  5524.     named by~\atcmd{i} will always be processed fully, regardless of
  5525.     any command-line 
  5526.     options.) This command will only work properly if the included text
  5527.     is a 
  5528.     complete module, or has no new-module commands in it at all.
  5529.     ^^:file!including!not printing:\cr
  5530. -i!&^^:\>{-i"!}: Tells \FWEAVE\ to not even read include files named by
  5531.     the \atcmd{I}~command.\cr 
  5532. -I&^^:\={-i}{-I}: Append a directory to the list of
  5533.     directories to be search for include files. (That list begins with
  5534.     the contents of the environment variable \\{FWEB\_INCLUDES} 
  5535.     ^^:\>{FWEB\UL INCLUDES}: 
  5536.     ^^:environment variables!\>{FWEB}!\>{FWEB\UL INCLUDES}: 
  5537.     if that     is defined.)  The argument of this option can also be a
  5538.     colon-delimited list of directories.\cr
  5539. \vfill\Eject
  5540. \clo{
  5541. -k\It{[letters]}&^^:\>{-k}: This option turns off the comment lines
  5542.     generated by \.{FTANGLE} during 
  5543.     \Ratfor\ statement translation. The `\.k' must be followed by a list of
  5544.     single lower-case characters (no quotes are required). If any of those
  5545.     characters is an asterisk, or if the list is empty,
  5546.     then all comment lines are suppressed.
  5547.     Otherwise, the characters serve as abbreviations for which \Ratfor\
  5548.     keyword the comment should be suppressed, as follows:
  5549. $$\def\htop#1{\vtop{\halign{\tt##\hfil&\ ---\ \&{##}\hfil\cr#1}}}
  5550. \htop{
  5551. b&break\cr
  5552. c&case\cr
  5553. t&default\cr
  5554. d&do\cr
  5555. f&for\cr
  5556. i&if\cr}
  5557. \qquad\qquad
  5558. \htop{
  5559. n&next\cr
  5560. p&repeat, until\cr
  5561. r&return\cr
  5562. s&switch\cr
  5563. h&where\cr
  5564. w&while\cr
  5565. For example, `\.{-kbn}' will suppress comments about the \&{break} and
  5566. \&{next} statements. ^^:Ratfor\actual\RATFOR!commands!deleting:\cr
  5567. -K\It{[letters]}&^^:\={-k}{-K}: As above, except that the list of
  5568.     abbreviations specifies which comments to include, rather than to
  5569.     suppress.\cr 
  5570. -l\It{[mmmm[:nnnn]]}&^^:\>{-l}: Echo the input line that the input driver has
  5571.     constructed, between lines~\It{mmmm} and~\It{nnnn}. Useful for
  5572.     debugging (especially for \FWEB\ itself), but 
  5573.     rather slow. The command 
  5574.     `\.{-l}\It{nnnnn}' echos all lines beginning with line~\It{nnnnn};
  5575.     if you just say~`\.{-l}', the echo starts with the first line.
  5576.     ^^:debugging!echoing input lines:\cr
  5577. \lstar -L\It{l}&^^:\={-l}{-L{\it l}}: Select language~$l$, where $l \in
  5578. \{\.c,\.n,\.r,\.x\}$.\cr 
  5579. \lstar -m\It{id[=text]}&^^:\>{-m}: The construction `\.{-m}\It{string}', where
  5580.     \It{string} does not begin 
  5581.     with~`\.4', allows one to define \WEB\ macros from the command line. To
  5582.     define the lower-case macro name `\.{test}' with null replacement
  5583.     text, say 
  5584.     `\.{-mtest}'. To give \.{test} a value, say `\.{-mtest=5}'. (No
  5585.     spaces are 
  5586.     allowed before or after the equals sign.) This is
  5587.     equivalent to saying at the beginning of the definition section of the
  5588.     first module \atcmd{m test 5}. (The equals sign in lieu of a space
  5589.     between 
  5590.     macro name and replacement text is allowed \It{only in definitions made
  5591.     from 
  5592.     the command line}, but allows you to avoid having to type quotes to 
  5593.     ensure 
  5594.     that the space is counted as part of the definition. For example,
  5595.     although 
  5596.     allowable, it's more cumbersome to type `\.{-m"test 5"}'.)
  5597.     Under~VMS, if 
  5598.     your macro name is upper case (a common convention), you must
  5599.     enclose the 
  5600.     definition in quotes, otherwise the name will be turned into lower case
  5601.     by~VMS. ^^:language!selecting:\cr
  5602. -m4&^^:\>{-m4}: Tells \WEAVE\ to understand the \.{m4} built-in commands.
  5603.     Also makes the 
  5604.     output extension~`\.{m4}' instead of~`\.{rat}', or~`\.{n4}' instead
  5605.     of~`\.{for}'. ^^:\>{m4}!understanding commands of:\cr 
  5606. -m;&^^:\>{-m;}: Tells \WEAVE\ to automatically append a
  5607.     pseudo-semicolon to 
  5608.     the end of \WEB\ macro definitions. \It{(Not recommended; insert
  5609.     pseudo-semis explicitly where necessary.)}
  5610. ^^:pseudo-!semicolon!appending automatically:\cr       
  5611. \vfill\Eject
  5612. \clo{
  5613. \lstar -n&^^:\>{-n}: Set the global language to \Fortran-77.
  5614.     ^^:language!global!Fortran--77\actual\FORTRAN--77:\cr  
  5615. -n9&^^:\>{-n9}: Set the global language to \Fortran--90.
  5616.     ^^:language!global!Fortran--90\actual\FORTRAN--90:\cr 
  5617. -n;&^^:\>{-n;}: For \Fortran--77, supply semicolons automatically.  (This
  5618.     is done automatically by default.)
  5619.     ^^:semicolons!automatic!Fortran\actual\FORTRAN:\cr 
  5620. -nb &^^:\>{-nb}: Number \&{do} and \&{if}~blocks in woven \Fortran\
  5621.     output.  This is helpful when the blocks are highly nested and/or long.
  5622.     The form of this numbering is defined by the \.{fwebmac}
  5623.     macro \.{\\Wblock}, which by default prints as `\Wblock{99}'.
  5624.     ^^{\CS{Wblock}} ^^:block numbers!\Fortran:\cr
  5625. \lstar -np&^^:\>{-np}:  Print semicolons in woven \Fortran\ output.  (Don't
  5626.     confuse with `\.{-n;}', described above.) ^^:semicolons!printing:\cr
  5627. -n\BS&^^:\>{-n\BS}:  Use free-form syntax for \Fortran--90; continue
  5628.     lines with a backslash. ^^:syntax!free-form!continuing with
  5629.     backslash:\cr 
  5630. -n\amp&^^:\>{-n\amp}:  As above, but continue lines with the
  5631.     ampersand. ^^:syntax!free-form!continuing with ampersand:\cr 
  5632. -n/&^^:\>{-n/}: In \Fortran, make '\.{//}'~denote the start of
  5633.     a short comment instead of  concatenation.  (One can always
  5634.     use~'\.{\\/}' ^^{\CS{/}} for concatenation.)
  5635.     ^^:comment!short!recognizing in 
  5636.     \FORTRAN:\cr 
  5637. -n!&^^:\>{-n"!}: In \Fortran, make
  5638.     `\.!'~denote the start of a short comment instead of the logical
  5639.     \.{NOT}.\cr 
  5640. \medalign
  5641. -o&^^:\>{-o}: Turn off \FWEAVE's mechanisms for overloading operators.
  5642.     ^^:operator!overloading!turning off:\cr
  5643. \lstar -P\It{[letter]}&^^:\={-p}{-P}:  Inform \FWEAVE\ about which processor,
  5644.     \TeX\ or \LaTeX, will be used to process the \.{.tex} file.  The
  5645.     default is~`\.{-PT}' (\TeX); to select \LaTeX, say~`\.{-PL}'.  The
  5646.     empty command~`\hbox{\.{-P}}' is equivalent to~`\.{-PT}'.
  5647.     ^^:\TeX\ processor, selecting:\cr
  5648. -p\It{cmd} &^^:\>{-p}: This absorbs a style-file command, which will be
  5649.     processed just before the local style file is read.  This option is
  5650.     useful in the initialization file \.{.fweb}; style-file options
  5651.     common to all jobs can be put there, leaving only things that
  5652.     customize individual runs to the local style file.\cr
  5653. -q&^^:\>{-q}: Turn off translation of \Ratfor\ commands into \Fortran.
  5654.     (This command is no longer supported.)\cr
  5655. \medalign
  5656. \lstar -r&^^:\>{-r}: Set the global language to~\Ratfor--77.
  5657.     ^^:language!global!Ratfor--77\actual\RATFOR--77:\cr 
  5658. -r9&^^:\>{-r9}:  Set the global language to~\Ratfor--90.
  5659.     ^^:language!global!Ratfor--90\actual\RATFOR--90:\cr  
  5660. -rb &^^:\>{-rb}: Number \&{do} and \&{if}~blocks in woven \Ratfor\
  5661.     output.  This is helpful when the blocks are highly nested and/or long.
  5662.     The form of this numbering is defined by the \.{fwebmac}
  5663.     macro \.{\\Wblock}, which by default prints as `\Wblock{99}'.
  5664.     ^^{\CS{Wblock}} ^^:block numbers!\Ratfor:\cr
  5665. -rg\It{params}&^^:\>{-g}: This option sets the parameters for the decision
  5666.     between the computed 
  5667.     \&{goto} and \&{if} statements for expanding the \Ratfor\
  5668.     \&{switch}. See the 
  5669.     discussion of \Ratfor\ for a detailed discussion of this command.\cr
  5670. \lstar -r;&^^:\>{-;}: For \Ratfor, make the input driver
  5671.     supply the semicolons automatically and use the ``obviously continued''
  5672.     syntax. (It's recommended that  this option not be used. When
  5673.     the programmer supplies the semicolons,  \Ratfor\ looks quite
  5674.     close to~\C.) ^^:semicolons!automatic!Ratfor\actual\RATFOR:\cr
  5675. -r/&^^:\>{-n/}: In \Ratfor, make '\.{//}'~denote the start of
  5676.     a short comment instead of  concatenation.  (One can always
  5677.     use~'\.{\\/}' for concatenation.)  ^^:comment!short!recognizing in
  5678.     \RATFOR:\cr
  5679. -r!&^^:\>{-r"!}: In \Ratfor, make `\.!'~denote the start of a short comment
  5680.     instead of the logical \.{NOT}. \cr 
  5681. \vfill\Eject
  5682. \clo{
  5683. \lstar -s&^^:\>{-s}: Print statistics about memory usage at the end of the
  5684.     run. ^^:statistics:\cr 
  5685. \lstar -sm\It{[nnn]}&^^:\>{-sm}: As above, but also print each dynamic memory
  5686.     allocation as it 
  5687.     is made. By default, only allocations $\ge 10,000$~bytes are shown.
  5688.     However, if you say ``\.{-sm\It{nnn}}'', then allocations
  5689.     $\ge$~\It{nnn}~bytes are 
  5690.     displayed. (On personal computers, this command also displays some
  5691.     indication of how much memory is available at the beginning and end
  5692.     of the     run.) ^^:memory, dynamic allocation of!statistics for:\cr 
  5693. \lstar -t\It{ln[\{\dots\}]}&^^:\>{-t}:  Truncate identifiers of language~$l$
  5694.     to length~$n$.  If braces are present, the dots signify a list of
  5695.     forbidden characters that are removed from the identifier before
  5696.     truncation.  (For example, `\.{-tn6\{\_\}}' removes any underscores,
  5697.     then truncates the result to 6~characters.)
  5698.     If this process results in non-unique identifiers, these will be
  5699.     listed.\cr 
  5700. \lstar -u\It{id}&^^:\>{-u}: This undefine command is the inverse of
  5701.   `\.{-m}'. Saying 
  5702.   `\.{-u\It{macroname}}' undefines a macro name either predefined by \WEB\ or
  5703.   defined earlier on the command line. Use this command with discretion. Don't
  5704.   undefine built-in macros such as \.{\_IF} since other things may also
  5705.   stop working because they use that built-in macro internally.
  5706.     ^^:macro!outer!undefining:\cr
  5707. -v&^^:\>{-v}: Tells \FTANGLE\ to make all comments verbatim; that is,
  5708.     retain them all in the output.
  5709.     ^^:comment!verbatim!making all:\cr
  5710. -W\It{letters}&Flag-setting commands that apply only to \FWEAVE.  Here
  5711.     \It{letters} may be one or more of the following:
  5712.     \clo{
  5713.     [&^^:\={-w[}{-W[}: Turn on special processing of bracketed array
  5714.         indices.\cr 
  5715.     f&^^:\={-wf}{-Wf}: Don't print format statements (\.{@f}) in woven
  5716.         output.\cr
  5717.     l&^^:\={-wl}{-Wl}: As above, but for limbo statements (\.{@l}).\cr
  5718.     m&^^:\={-wm}{-Wm}: As above, but for macro definitions (\.{@m}).\cr
  5719.     v&^^:\={-wv}{-Wv}: As above, but for operator overloading 
  5720.         (\.{@v}).\cr     
  5721.     w&^^:\={-ww}{-Ww}: As above, but for identifier overloading
  5722.         (\.{@W}).\cr
  5723.     }\cr
  5724. \lstar -w\It{[file\_name]}&^^:\>{-w}: With no argument,
  5725.     do not print ``\.{\\input
  5726.     fwebmac.sty}'' as the first line of the \.{.tex} output file. 
  5727.     (This may be useful if you have some other macro package that needs for
  5728.     some tricky reason to be loaded before \.{fwebmac}.)  With an
  5729.     argument, print instead ``\.{\\input \It{file}\_\It{name}}''.
  5730.     ^^:\>{fwebmac}!\>{.sty}!not printing:\cr
  5731. \vfill\Eject
  5732. \clo{
  5733. \lstar -x\It{[letters]}&^^:\>{-x}: Reduce or eliminate printed
  5734.   cross-reference information.  The optional letters refer to which piece of
  5735.   information should \It{not} be
  5736.   printed; they can be one or more of~'\.c', 
  5737.   '\.i', '\.m', or~'\.*', referring respectively to the table of contents,
  5738.   index, module list, or all cross-reference information.  The 
  5739.   command~`\.{-xi}' means ``do not print the index, but print the module list
  5740.   and   
  5741.   table of contents''. The command~`\hbox{\.{-xim}}' means ``print only the
  5742.   table of 
  5743.   contents, as does~`\.{-Xc}' (see the next option) or even~\hbox{`\.{--xc}'}.
  5744.   The command~`\.{-x}' is 
  5745.   equivalent to~`\.{-x*}', which means ``print nothing''.
  5746.     ^^:cross-references!suppressing:
  5747.     ^^:index!suppressing:\cr
  5748.     ^^:module list!suppressing:\cr
  5749.     ^^:table of contents!suppressing:
  5750. \lstar -X\It{[letters]}&^^:\={-x}{-X}: Print selected cross-reference
  5751.   information; equivalent to~`\.{--x}'.  To suppress printing of the index
  5752.   and module list, but retain the table of contents, say~`\.{-Xc}'.  The
  5753.   default is `\.{-X*}', which means print everything.
  5754.     ^^:index!printing:\cr
  5755. \lstar -y\It{a[a]nnnn}&^^:\>{-y}: Allocate dynamic memory.
  5756.   The format is \.{-y}\It{aa}$nnnnn$, where
  5757.   \It{aa}~stands for a one- or two-character abbreviation for the relevant
  5758.   array and $nnnnn$~is the number of elements in the array. See the section
  5759.   below on dynamic memory allocation for more details.
  5760.     ^^:memory, dynamic allocation of!syntax:\cr
  5761. -Z\It{[letters]}&^^:\={-z}{-Z}: Print default value of style-file parameters.
  5762.   If \It{letters} are absent, information about all parameters is displayed.
  5763.   If \It{letters} are present, information about only parameters beginning
  5764.   with \It{letters} is displayed.  
  5765.     ^^:style file!parameters!default values of:\cr
  5766. -z\It{[name]}&^^:\>{-z}: Specify a new name for the style file, as in
  5767.   \.{-z\It{newstyle}}. (The default name is \.{fweb.sty}.) If no name is
  5768.   given, the null file is assumed. ^^:style file!new name for:\cr
  5769. \lstar -.&^^:\>{-.}:  In \Fortran\ or \Ratfor, do not recognize ``dot
  5770.     constants'' ^^{constant!dot}
  5771.     such as `\.{.eq.}'.  (Use the modern \WEB\ alternatives
  5772.     such as `\.{==}'.) \cr
  5773. \lstar -\BS&^^:\>{-\BS}: Explicitly escape continued strings.  Without this
  5774.     option, continued strings must begin in the first column of the
  5775.     next line.  With this option, the continuation line may begin with
  5776.     white space followed by an escape character; the string continues
  5777.     after the escape character.  In~C, the escape character is the
  5778.     backslash; in \Fortran\ or \Ratfor, it is selected by~`\.{-n\&}'
  5779.     or~`\.{-n\\}'. ^^:strings!continuing!with explicit escape:\cr 
  5780. \lstar -(&Continue parenthesized strings (arguments of certain built-in
  5781.     commands) with backslashes. ^^:strings!parenthesized!continuing:\cr
  5782. \lstar -:\It{nnnnn}&^^:\>{-":}: The command `\.{-:}\It{nnnnn} sets the
  5783.     starting automatic statement number for \Fortran\ and \Ratfor.
  5784.     ^^:statement!number!setting:\cr
  5785. ->\It{[l=][name]}&^^:\>{->}: Redirect output. The command~`\.{->}' (or its
  5786.     synonym~`\.{-=}') 
  5787.     with no argument redirects output to the terminal. The most general
  5788.     form is 
  5789.     `\.{->\It{l}=\It{name}}', which redirects output for language~\It{l}
  5790.     to the file \It{name}. See the section on output redirection for
  5791.     more details. ^^:output!redirection:\cr 
  5792. -=\It{[l=][name]}&^^:\>{-=}: Redirect output; same as~`\.{->}'. Useful under
  5793.     \Unix, because '\.>'~has special significance to the shell.\cr 
  5794. \lstar -\#&^^:\>{-\PM}: Turn off commands about line numbers and module
  5795. names in tangled output. ^^:line!numbers!turning off:\cr
  5796. \lstar -+&^^:\>{-+}: In \Fortran\ or \Ratfor, don't allow the compound
  5797.     assignment operators `\.{++}', `\.{--}', `\.{+=}', `\.{-=}',
  5798.     `\.{*=}', or 
  5799.     `\.{/=}'. ^^:operators!compound assignment!not recognizing:\cr 
  5800. -/&^^:{\>{-/}}: In both \Fortran\ and \Ratfor, make `\.{//}'~denote the
  5801.     start of a short comment instead of  concatenation.  (One can
  5802.     always use~'\.{\\/}' ^^{\CS{/}} for concatenation.) \cr
  5803. -!&^^:{\>{-"!}}: In both \Fortran\ and \Ratfor, make 
  5804.     `\.!'~denote the start of a short comment instead of the logical
  5805.     \.{NOT}.\cr 
  5806. ^^)options!command-line)
  5807. \dsubsection Initialization file ({\tt .fweb} or {\tt fweb.ini}).
  5808. ^^(file!initialization( 
  5809. Commonly used options can be placed into an initialization file instead of
  5810. repeated each time on the command line. The name of this file is determined
  5811. as follows.  On systems that support environment variables (^{logical names}
  5812. under VMS), if the
  5813. environment variable \.{FWEB\_INI} 
  5814. ^^:\>{FWEB\UL INI}: ^^:environment variables!\>{FWEB}!\>{FWEB\UL INI}:
  5815. is defined, then that is the name of the ini file.  As examples,
  5816. {\codemode
  5817. setenv FWEB_INI .fweb \qquad{\it (\Unix)}
  5818. define FWEB_INI .fweb \qquad{\it (VMS)}
  5819. \noindent This should just be the raw file name, such as \.{.fweb}; no path
  5820. should be specified, since
  5821. the initialization file must be placed into the
  5822. user's \It{home directory} (\It{not} the current one). 
  5823. If \.{FWEB\_INI} is not defined, then if the operating system allows a file
  5824. name to begin with a period the name is
  5825. ``\.{.fweb}''.  ^^:\>{.fweb}: (It begins with a dot so it will be invisible
  5826. by default on \Unix\ systems.) Otherwise, as on the IBM-PC, the name is
  5827. instead ``\.{fweb.ini}''. ^^:\>{fweb.ini}:
  5828. Any argument that
  5829. can be placed on the command line 
  5830. can be placed into \.{.fweb}. (Presently, they cannot be continued across
  5831. newlines.) 
  5832. For options that on the command line would begin with a hyphen, one can
  5833. either use the hyphen or, alternatively, a plus sign. Ini options beginning
  5834. with a plus sign are processed \It{before} the command-line arguments; ini
  5835. options beginning with a hyphen are processed \It{after} the command-line
  5836. arguments. Entries beginning with anything other than a hypen or plus sign
  5837. are interpreted as file names, and are processed after any file names found
  5838. on the command line.  Usually one uses the plus sign for ini file options,
  5839. so that one can override them on the command line if desired.
  5840. Comments may be used in the ini file. ^^:comment!in initialization file:
  5841. They follow the same format as those
  5842. for \TeX: namely, anything beginning with a per~cent sign is ignored to the
  5843. end of the line.
  5844. Thus, a sample initialization file is
  5845. {\codemode
  5846. % Sample FWEB initialization file.
  5847. +PL % LaTeX will be used.
  5848. +v % Retain all comments in tangled output.
  5849. +n9 % Assume Fortran--90,
  5850. +n\\ %   with free-form syntax.
  5851. ^^)file!initialization)
  5852. \dsection ADVANCED FEATURES.[15.4] ^^(features!advanced(
  5853. Knowledge of the following features is not necessary for simple uses of the
  5854. \WEB\ system.  However, they can be very useful in unusual applications.
  5855. It is particularly helpful to learn how to use the style file.
  5856. \ddsubsection Input and output redirection. ^^(redirection(
  5857. ^^[input!redirection]^^[output!redirection] 
  5858. As we have explained, the \FWEB\ processors read their input by default
  5859. from a file with extension \.{.web}.
  5860. \FWEAVE's \TeX\ output goes by default into a file with
  5861. extension \.{.tex}; \FTANGLE's compilable output goes by default into
  5862. \.{.sty}, \.{.c}, \.{.rat}, or \.{.for} files. (Under \Unix, the latter two
  5863. are~\.{.r} 
  5864. and~\.{.f}.) Occasionally, one may wish to override these defaults. It is
  5865. most useful to redirect the output.  This can be done with the command-line
  5866. option~`\.{->}' or its synonym~`\.{-=}'. The bare command~`\.{->}'
  5867. redirects all output to the terminal. The command
  5868. ``\hbox{\.{->}\It{file\_name}}'' redirects all output to the file
  5869. \It{file\_name}.
  5870. (For \FTANGLE, this kind of redirection is not very useful if you're
  5871. working with more than one 
  5872. language.) The command ``\hbox{\.{->}$l$\.=\It{file\_name}}'' redirects output
  5873. intended only for the file associated with
  5874. language~$l$, where $l$~is one of~\.x, \.c, \.r, or~\.n. (Use~\.n if you're
  5875. working with \Ratfor; the symbol refers to the output file that is being
  5876. created, not the language from which things are being produced.) If
  5877. \It{file\_name} contains the symbol~'\.\#', that 
  5878. symbol is expanded into the name of the web file. Thus, for example, if you
  5879. say ``\hbox{\.{ftangle test ->\#.out}}'', all output is redirected into the
  5880. file \.{test.out}. 
  5881. One should not confuse \FWEAVE's redirection with the redirection provided by
  5882. \Unix\ shells. The default \FWEB\ processors cannot be used as \Unix\ filters:
  5883. by default they neither take their input from the standard input nor write
  5884. it to the standard output; they take it from, and write it to, files.
  5885. (Information and error messages are always written to the standard output.)
  5886. \FWEB\ command~`\.{->}' makes \FWEB\ write all output to the standard output;
  5887. that output could then be redirected again by the \Unix\ shell. Thus, the
  5888. \Unix\ command ``\.{ftangle test -= >test.out}'' puts all output, both
  5889. information and compilable code, into \.{test.out}. If you didn't use the
  5890. `\.{-=}'~option, you would just get the information messages in \.{test.out}.
  5891. Incidently, it should now be clear why the command~`\.{-=}' was introduced as
  5892. a synonym for~`\.{->}'. \Unix\ would interpret the~'\.>' as a redirection
  5893. command to the shell, and it's cumbersome to type~`\.{-\\>}' when you're in a
  5894. hurry.
  5895. Input redirection is also possible; just replace the web file name by
  5896. ``\.{stdin}'' ^^{\>{stdin}}
  5897. or, equivalently, a single hyphen. Thus, the command
  5898. ``\.{ftangle stdin}'' or equivalently ``\.{ftangle -}'' reads from the
  5899. standard  
  5900. input (usually the terminal). (The analogous command for \FWEAVE\ doesn't
  5901. work in a reasonable way, since \FWEAVE\ makes two passes over the input
  5902. file.) Thus, you can force \FTANGLE\ to be a \Unix\ filter by saying
  5903. ``\.{ftangle stdin -=}''. For example, if you say ``\.{ftangle <test.in
  5904. stdin -= >test.out}'', input will be taken from \.{test.in} and written to
  5905. \.{test.out} (along with the information messages). Note that ``\.{ftangle
  5906. <test.in stdin}'' is equivalent to just ``\.{ftangle test.in}''; however,
  5907. ``\.{ftangle test.in -= >test.out}'' is not quite equivalent to ``\.{ftangle
  5908. test.in >test.out}''. The former puts everything into \.{test.out}; the
  5909. latter just puts the information messages into \.{test.out}.
  5910. ^^)redirection)
  5911. \dsubsection Customizing \FWEB: The style file {\tt fweb.sty}.[15.2.4]
  5912. ^^(customization( ^^[style file]
  5913. It is possible to customize various aspects of \FWEB's behavior.
  5914. The original motivation was to provide some control over the appearance of
  5915. the index; the same mechanism can also be used to change the definitions of
  5916. many of \FWEB's '\.@'~commands and to customize other facets of \FWEB's
  5917. behavior.  (Customizing the production rules is not presently implemented,
  5918. but may be in the future.)
  5919. \parinsert{3}{4}{0.5}
  5920. One can customize behavior with the style file {\ssbf fweb.sty}.
  5921. The solution that
  5922. has been adopted follows that for the utility program
  5923. \.{makeindex}\cite{makeindex}: ^^{\>{makeindex}}
  5924. namely, a \It{style file} can be supplied. If present, the style file
  5925. is read in after the command line is parsed.  This file is located in the
  5926. directory specified by the environment variable
  5927. \.{FWEB\_STYLE\_DIR}, ^^:\>{FWEB\UL STYLE\UL DIR}:
  5928. ^^:environment variables!\>{FWEB}!\>{FWEB\UL STYLE}:
  5929. if that is defined.  Otherwise, it is assumed that the style
  5930. file is in the current directory. The default name of the style
  5931. file is \.{fweb.sty}; ^^:\>{fweb.sty}:
  5932. that can be overridden by using the command-line option~`\.{-z}'. ^^{\>{-z}}
  5933. (If you say ``\.{-z}'' with no argument, the style file is
  5934. null; specify an alternate name by saying ``\.{-z\It{name}}''.)
  5935. Its contents consists of a
  5936. sequence of keywords and keyword arguments, in essentially free-form
  5937. format.  The keywords and arguments are separated by white space, and/or
  5938. optionally an equals sign.  Also, periods in keywords are equivalent to
  5939. underscores.  Thus, the following two lines are equivalent:
  5940. {\codemode
  5941. lethead_flag 1
  5942. lethead.flag = 1
  5943. \noindent (The form with the period is preferred; the intent is to emulate
  5944. structure references in~\C.)
  5945. The arguments can be either single characters (surrounded by single
  5946. quotes), character strings (surrounded by double quotes), boolean (0~for
  5947. \\{NO}, 1~for \\{YES}), or integers
  5948. (optionally followed by a trailing \.L for \&{long}). As in~C, characters
  5949. can be escaped with a backslash. Thus, for example, to include a double
  5950. quote and a newline inside a string, say \.{"\dots\\"\dots\\n\dots"}.
  5951. Comments may be included in the style file. ^^:comment!in style file:
  5952. They follow the \TeX\ format:
  5953. everything from a per~cent character to the end of line is ignored.
  5954. At present, there can be just one style file. No \.{include} command is
  5955. allowed within a style file. (Someday these restrictions may be removed.)
  5956. In the following discussion, the style-file vocabulary 
  5957. ^^[style file!vocabulary]
  5958. is presented in functional groups.  For an alphabetical listing of all of
  5959. the vocabulary entries, see the index entry ``style file, vocabulary''.
  5960. Also, to save space, the actual list of keywords associated with each group
  5961. is not given here, but is rather presented in Appendix~M.  Here, we content
  5962. ourselves with a summary of the available features and some examples of
  5963. their use. 
  5964. \dsubsubsection Customizing the index, {etc.}.
  5965. First there are keywords related to customizing the index, module list, and
  5966. miscellaneous features that are
  5967. recognized in the style file. (In conjunction with these keywords, you
  5968. should also study the \.{\\Wcon} macro in \.{fwebmac.web}.)
  5969. ^^[index!customizing] ^^{\CS{Wcon}} ^^{\>{fwebmac}!\>{.web}}
  5970. Note that during its processing \FWEB\ uses several temporary files to
  5971. accumulate the index, list of modules, and the table of contents.  By
  5972. default, these are called \.{INDEX.tex}, ^^:\>{INDEX.tex}:
  5973. \.{MODULES.tex}, ^^:\>{MODULES.tex}:
  5974. and \.{CONTENTS.tex}.  ^^:\>{CONTENTS.tex}:
  5975. When working with more than 
  5976. one file at a time, it is desirable to change these names to include the
  5977. file name.  This can be done by incorporating the
  5978. character~`\.{\#}' into the style-file field; this character is
  5979. translated into the root name of the web file.  For example, a typical
  5980. style file might contain the entries
  5981. {\codemode
  5982. index.tex "#.ndx"
  5983. modules.tex "#.mds"
  5984. contents.tex "#.cts"
  5985. %\input index.stl
  5986. As an example, here is how one might beautify \FWEAVE's index (see
  5987. Appendix~M, ``Customizing \FWEAVE's index''):
  5988. {\codemode
  5989. % --- SAMPLE STYLE FILE fweb.sty ---
  5990. limbo "\\\\input fweb" % Input fweb.tex automatically just after fwebmac.sty.
  5991. % If the source file is test.web, make the name of the index file \.{test.ndx}.
  5992. index.tex "#.ndx"
  5993. % Separate index entries by \\letter\{...\}. See fweb.tex for \\letter.
  5994. lethead.prefix "\\\\letter\{" 
  5995. lethead.suffix "\}\\n"
  5996. lethead.flag -1 % Use lower-case letters.
  5997. \noindent The file \.{fweb.tex} contains \TeX\ macros used for producing
  5998. the woven output of the \FWEB\ sources themselves.  In it, one finds the
  5999. definition of \.{\\letter}, which in part looks like 
  6000. {\codemode
  6001. \\def\\letter#1\{\\hbox\{\dots\\kern2em--- \{\\tt #1\} ---\}\\smallskip\}
  6002. \noindent With this definition, each index entry will be preceded by a line
  6003. that contains a construction such as \hbox{``--- {\tt a} ---''} to denote the
  6004. start of each new letter group.
  6005. For further information about customizing the module list and table of
  6006. contents, see App.~M, ``Customizing
  6007. \FWEAVE's module list'' and ``Customizing \FWEAVE's table of contents.''
  6008. %\input modules.stl
  6009. %\input contents.stl
  6010. \FWEB\ can attach cross-reference information as subscripts to various
  6011. entities such as function names.  \FWEB\ will do this by default for some
  6012. entities, but not for others.  To change the defaults, see App.~M,
  6013. ``Customizing cross-reference subscripts.''
  6014. %\input subs.stl
  6015. When \FWEAVE\ writes the \.{.tex} file, it emits the names of
  6016. various macros that are used by the \FWEB's macro package \.{fwebmac.sty}.  
  6017. In some cases it is desirable to have some control over these names without
  6018. recompiling \FWEB.  For further information, see App.~M, ``Overriding or
  6019. completing definitions in \.{fwebmac.sty}.''
  6020. %\input formats.stl
  6021. There are various miscellaneous customization commands for \FWEAVE.  One
  6022. important one is the \.{limbo} command, which specifies \TeX\ material that
  6023. \FWEAVE\ should print at the beginning of the limbo section.  For example,
  6024. {\codemode
  6025. limbo "\\input fweb"
  6026. \noindent writes the line ``\.{\\\\input fweb}'' somewhere soon after the
  6027. first line of the output file, which is generally ``\.{\\\\input
  6028. fwebmac.sty}''.  This provides a way of including a user's macro file in
  6029. addition to the default one of \FWEB.  For more information, see App.~M,
  6030. ``Miscellaneous customization commands for \FWEAVE.''
  6031. %\input wmisc.stl
  6032. A variety of parameters are useful only for \FTANGLE.  These include the
  6033. \.{cdir\_start} commands, which specify default text that should be output
  6034. at the beginning of every compiler directive (initiated by~\atcmd{?}).
  6035. Also, one can specify the extension for the output file for each language
  6036. with the \.{suffix} command.  For more information, see App.~M,
  6037. ``Customizations for \FTANGLE.''
  6038. %\input t.stl
  6039. For a few miscellaneous commands, see App.~M, ``Miscellaneous
  6040. customizations for both \FTANGLE\ and \FWEAVE.  
  6041. %\input wtmisc.stl
  6042. \dsubsubsection Automatic file name completion. ^^(file name!completion(
  6043. When the `\.{-e}'~option is in effect, ^^:\>{-e}:
  6044. file names that contain no period
  6045. will be completed automatically by using extensions from the 
  6046. style-file entries described in App.~M, ``Automatic file-name completion.''
  6047. The entries such as \.{ext.web} are strings that 
  6048. contain a blank-delimited list of extensions. Complete file names are
  6049. created by applying each of these extensions in turn to the original name;
  6050. the first full name that matches a directory entry is used.  Thus, if one
  6051. says ``\.{ext.change = "ch chng"}'', then if the `\.{-e}'~option is in
  6052. effect the command line ``\.{ftangle test test}'' means to tangle
  6053. \.{test.web} with the change file \.{test.ch} or, if that does not exist,
  6054. with the change file \.{test.chng} if that exists.
  6055. %\input auto.stl
  6056. ^^)file name!completion)
  6057. \ddsubsubsection Custom colors. ^^(color(
  6058. \parinserto{3}{4}{0.33}
  6059. ``Color is obviously a frill.  Have fun...''
  6060. \FWEB\ supports a \It{restricted, experimental, and incomplete}
  6061. color enhancement mode. Color output is 
  6062. not considered to be essential, since \FWEB\ is not interactive and usually
  6063. prints only a small amount of information to the terminal.  Nevertheless,
  6064. color can be usefully used for emphasis---e.g., for error messages, file
  6065. names, etc.---and those who have spent
  6066. considerable amounts of money on a color monitor like to feel that they're
  6067. getting their money's worth.  Unfortunately, color manipulations are not
  6068. fully standardized.  The X~Terminal System standardizes one mode of
  6069. manipulating color, and someday there may be an X~version of \FWEB.
  6070. Meanwhile, \FWEB\ can be taught to translate color commands into \.{VT100}
  6071. escape sequences, so various highlighting modes such as underlining, double
  6072. intensity, etc., can be used with standard terminal emulators such as
  6073. \.{xterm}. 
  6074. Here's how it works.  The information output by \FWEB\ has been classified
  6075. into various types; each type can be assigned a different color.  For
  6076. example, referring to the list below,  error messages have the type
  6077. \.{color.error}.  Each type has a default color that can be overridden
  6078. in the style file, as in 
  6079. {\codemode
  6080. color.error = "red"
  6081. \noindent Ultimately, these colors will
  6082. correspond to R--G--B triplets.  However, in this restricted implementation
  6083. they are mapped to
  6084. \.{VT100} escape sequences.  There are also defaults for these, or they can
  6085. be set in the style file, as in
  6086. {\codemode
  6087. color.red = "md mr"
  6088. \noindent (Note the space separating multiple escape sequences.)
  6089. The abbreviations such as~``\.{md}'' for the escape sequences are those
  6090. standardized 
  6091. by \.{termcap} files; in \Unix, see the man page for \.{termcap}, or in
  6092. \.{emacs} see the \.{termcap} menu item.  Thus, the previous example means
  6093. that red information fields will be displayed as double intensity reverse
  6094. video. 
  6095. Whether any kind of color manipulation is operative is specified by the
  6096. variable \.{color.mode}.  When \.{color.mode = 0}, no color manipulations
  6097. are done. When \.{color.mode = 1}, a ``bilevel'', essentially
  6098. dual-intensity palette is selected, with the default sequences as below.
  6099. When \.{color.mode = 2}, true color is supposed to be selected; however, at
  6100. present, that also corresponds to a particular mapping between colors and
  6101. escape sequences.  Experiment to see what happens.
  6102. Color is obviously a frill.  Have fun playing with it, but don't forget to
  6103. do some real work too.  For the list of available commands, see App.~M,
  6104. ``Colors''. 
  6105. %\input colors.stl
  6106. ^^)color)
  6107. \ddsubsubsection Customizing control codes.
  6108. Now we describe how to customize \FWEB's control codes. \It{This feature is
  6109. still experimental, and is recommended for advanced users only.} (No,
  6110. cancel that; \It{it's not recommended at all}.) Generally, the default
  6111. codes are 
  6112. adequate. However, occasionally one might want to change the code that maps
  6113. to a particular operation.  The format is the keyword listed below,
  6114. followed by a (double-quoted) character string containing all the symbols
  6115. that you wish to map onto the operation associated with the keyword. For
  6116. example, if you want to allow the use of any of~\atcmd{a}, \atcmd{A},
  6117. or~\atcmd{j} to denote the start of the unnamed module, you would use a
  6118. style file entry
  6119. {\codemode
  6120. begin_code "aAj"
  6121. \noindent In the above, replace the string~\.{"aAj"} by~\.{"j"} if you want
  6122. to use only~`\.{@j}'.
  6123. There may be no
  6124. overlaps---i.e, one can't map the same character onto two different
  6125. operations. Also, because of design decisions built into the original
  6126. \WEB, some commands with different meanings are all mapped onto the same
  6127. fundamental operation, such as the commands~\atcmd{\ } and~\atcmd{*}. At
  6128. present, such commands cannot be remapped.  
  6129. For more information, see App.~M, ``Customizing \FWEB's control codes.''
  6130. ^^[control codes!customizing]
  6131. %\input ccodes.stl
  6132. ^^)customization)
  6133. \ddsubsection Dynamic memory allocation. ^^(memory, dynamic allocation of(
  6134. ^^[allocation, dynamic memory]
  6135. \FWEB's internal buffers and arrays are allocated dynamically (at run time,
  6136. rather than at compile time). Although default lengths are built into
  6137. \FWEB\ and will be adequate for most applications (in particular, for
  6138. running the \FWEB\ processors on themselves and each other), the facility
  6139. does exists 
  6140. to change those. (One might need to enlarge certain arrays for an unusually
  6141. large job, or one might need to shrink things to make them fit on a
  6142. personal computer.) Dynamic memory allocation is done with the 
  6143. command-line option~`\.{-y}'.
  6144. ^^:\>{-y}:
  6145. This is followed by a one- or two-character
  6146. abbreviation for the array in question, followed in turn by the number of array
  6147. elements (not bytes) to allocate, as in `\.{-yb150000}'.  These
  6148. abbreviations are described more fully in Appendix~N.
  6149. In general, \It{you probably shouldn't fiddle around with dynamic memory
  6150. allocation unless you understand the inner workings of \FWEB\ in
  6151. considerable detail}. However, someday one of the processors may complain
  6152. that it ran out of memory for one reason or another; then you may wish to
  6153. try overriding the default.  Usually the error message will tell you which
  6154. abbreviation to use as well as its maximum allowed value.  (Beware: if it's
  6155. the macro buffer that overflowed, there's probably something wrong with the
  6156. macro, or there's a bug in \FTANGLE.)  Sometimes, however, the message will
  6157. simply tell you that it ran out of memory, but it won't deign to advise you
  6158. which array to shrink.  In this case, proceed as follows.  First, determine
  6159. the default allocations by using the `\.{-y}'~option with no arguments.  (Query
  6160. just one option by saying `\.{-y\It{a[a]}}'.)
  6161. Alternatively, one can run a very small test code with the
  6162. `\.{-s}~option; that reports statistics about the principal buffers at the
  6163. end of the run.  (If you want even more information, use the
  6164. option~`\.{-sm}' to obtain a detailed accounting of the dynamic memory
  6165. allocations as they occur.)  Then, attempt to shrink one or more of the
  6166. largest buffers by using the appropriate `\.{-y\It{a[a]nnnnn}}'~option;
  6167. refer to Appendix~N. 
  6168. After one determines an appropriate set of allocations, one typically puts
  6169. the allocation commands into the ini file 
  6170. \.{.fweb}, since the same parameters would likely be used for many runs.
  6171. ^^)memory, dynamic allocation of)
  6172. \ddsubsection Debugging. ^^(debugging(
  6173. There is no denying that the use of named sections (in this discussion we
  6174. explicitly distinguish between modules and sections: modules are the
  6175. concatenations of all sections with the same name) significantly helps one
  6176. to write structured, readable code. In many cases, one can use a named
  6177. section in place of a function call, with all the readability and helpful
  6178. cross-reference information of the former but without the overhead of the
  6179. latter. Unfortunately, the absence of an explicit function call means
  6180. that the job of debugging is somewhat more annoying. One might want to set a
  6181. breakpoint at the beginning of the section. Without a function call one must
  6182. set a breakpoint at a line number, but this is the line number of the
  6183. output file as understood by the compiler, not the \WEB\ file; that line
  6184. number may be difficult to determine.
  6185. \FWEB\ provides a partial, experimental solution to this
  6186. problem. If the user defines \It{from the command line} the \It{breakpoint}
  6187. macro \.{\_BP(num,name)},
  6188. ^^:\>{\UL BP}:
  6189. then \FTANGLE\ will insert at the beginning of
  6190. every section
  6191. that begins with a left brace the expansion of \.{\_BP}, with \\{num}
  6192. replace by the section number and \\{name} replaced with the (possibly
  6193. truncated) name  (surrounded by quotes) of the module to which the section
  6194. belongs. Thus, the user has
  6195. complete flexibility to develop his own tracing/breakpointing system. For
  6196. example, suppose the C~user issues the command-line option
  6197. `\.{-m\_BP(num,name)=trap(num,name);}'. Then each section that begins with a
  6198. left brace will begin with a call to the function \\{trap}, which the user
  6199. can define as he pleases. He might call another function directly from the
  6200. debugger to add or remove a section number from a list of breakpoints, then
  6201. arrange to have \\{trap} pause when only the turned-on sections are
  6202. encountered.  Exactly how this would work depends in some detail on the
  6203. debugger available, but the philosophy itself is quite general. Casual
  6204. users of \WEB\ will probably not bother with all this, but for those who
  6205. work with large codes this feature may be essential.
  6206. C and \Ratfor\ users will have no trouble understanding the restriction to
  6207. sections beginning with a left brace; the debugging call needs to be tucked
  6208. away inside a compound statement so that it does not inadvertently appear
  6209. to be a single statement following a loop and thereby change the program
  6210. logic. \Fortran\ users ordinarily do not need to use braces; however, if
  6211. they do not, this breakpointing mechanism will not function.  Happily,
  6212. straight
  6213. \Fortran\ will expand braces just fine---it just ignores them on
  6214. output---so things will work consistently in all languages if all sections
  6215. that are to be interpreted as ``call-less functions'' are delimited by
  6216. braces.
  6217. However, C~users will object that one can't always insert an executable
  6218. statement immediately after a left brace, because a declaration statement
  6219. might be coming up. The solution to this is to replace the left brace
  6220. by~\atcmd{\{}. ^^{\>{@\LB}} 
  6221. This expands into a left brace, but also prevents the default
  6222. insertion. To insert a breakpoint later in such a
  6223. section, use the command~\atcmd{b} at the desired place. For example,
  6224. ^^{\>{@b}}
  6225. {\codemode
  6226. @ An example of inserting breakpoint commands for debugging.
  6227. @<Test@>=
  6228. int i;
  6229. \It{executable code};
  6230. @b @% Note that one can insert a breakpoint at more than one place.
  6231. For an example of section breakpointing functions suitable for use with
  6232. C~programs, see the example file \.{breakpt.web}. ^^{\>{breakpt.web}}
  6233. It would be easy to
  6234. adapt this scheme for \Fortran\ programs as well. That demo also
  6235. illustrates the use of the built-in functions \.{\_SECTIONS} and~\.{\_MODULES}.
  6236. ^^{\>{\UL SECTIONS}} ^^{\>{\UL MODULES}}
  6237. ^^)debugging)
  6238. ^^)features!advanced)
  6239. \section USAGE TIPS and SUGGESTIONS.[16.2] ^^(usage suggestions(
  6240. In this section we collect various tips and suggestions to help one make
  6241. full use of the \WEB\ system.  \It{(There's more to come here!)}
  6242. \subsection Converting an existing code to {\tt FWEB}.
  6243. ^^(\>{FWEB}!converting to( 
  6244. In summary, to convert an existing code to \FWEB, you should do the
  6245. following. (The following simple procedure assumes that you put all the
  6246. subroutines into the unnamed module. However, other more elaborate schemes
  6247. are possible.)
  6248. {\narrower\newfeature
  6249. \feature. Place invisible commentary ^^{commentary!invisible}
  6250. about the author, version, etc.\ at the beginning of the source file by
  6251. bracketing it with~\atcmd{z\dots@x}.  The~\atcmd{z}~must be the first two
  6252. characters of the file.
  6253. \feature.  Next, set the language by including a command such as~\atcmd{n}.
  6254. \feature. Place an \atcmd{a}~command before each program unit (e.g., main
  6255. \&{program}, \&{subroutine}, or \&{function}).
  6256. \feature. Before each~\atcmd{a}, place an~\atcmd{*} or \atcmd{\ }~command,
  6257. followed by \TeX\ documentation about that particular section of code.
  6258. \feature. If you have program units longer than about twelve lines, either
  6259. make them function calls, if you can afford the overhead and can impart
  6260. sufficient information via the function name, or break them up into shorter
  6261. fragments by using named modules. Insert the command \atcmd{<\It{Name of
  6262. module}@>} in place of the fragment you're replacing, then put that
  6263. fragment somewhere else, prefaced by~\atcmd{\ } and \atcmd{<\It{Name of
  6264. module}@>=}.
  6265. \feature. Make sure your comments are valid \TeX. (You can't have things
  6266. like raw underscores or dollar signs in comments, since those cause \TeX\
  6267. to take special actions.)
  6268. \feature. Beautify and clarify your documentation by using code mode
  6269. (enclosing stuff between vertical bars) liberally within your \TeX. 
  6270. \feature. After you've seen the woven output, you may need to go back and 
  6271. format a few identifiers or section names so that \FWEAVE\ understands them
  6272. properly, or you may need to insert some pseudo-semicolons,
  6273. pseudo-expressions, or pseudo-colons.
  6274. \feature. Consider using the built-in macro preprocessor to make your code
  6275. more readable---for example, replace raw numerical constants by symbolic
  6276. names. 
  6277. \feature. If you are a \Fortran\ user,  for ultimate readability
  6278. consider converting to \Ratfor. The initial annoyance is getting rid of
  6279. column~6 continuations. With the aid of a good editor, this can be done
  6280. simply. For example, in \.{EMACS} one can replace the regular expression
  6281. [carriage return, five spaces, something not equal to space, tab, or~0]
  6282. with [backslash, carriage return, six spaces]:
  6283. {\codemode
  6284. M-x replace-regexp RET
  6285. C-q C-j \.{\ \ \ \ \ }[\^\.\ tab 0]RET
  6286. \\\\ C-q C-j \.{\ \ \ \ \ \ }RET
  6287. \noindent Get rid of the keywords such as \&{then} or \&{end if} in favor
  6288. of braces. Change singly-quoted character strings to doubly-quoted ones.
  6289. ^^)\>{FWEB}!converting to)
  6290. \subsection Programming tips and other suggestions. ^^(programming tips(
  6291. \It{This section will be enlarged in the future!}  Meanwhile, please feel
  6292. free to contact \.{krommes@princeton.edu} for help and advice, and to
  6293. suggest items to include here.
  6294. ^^{help!obtaining} 
  6295. \newfeature
  6296. \feature. Periodically check \.{lyman.pppl.gov:/pub/fweb/READ\_ME} for bug
  6297. reports 
  6298. ^^{bug reports}
  6299. ^^{programming tips!bug reports}
  6300. and other news.
  6301. \feature. Most options in \.{.fweb} ^^{programming tips!initialization options}
  6302. ^^{options!initialization}
  6303. should begin with '\.+' so they can be
  6304. overridden by command-line options for the job itself.
  6305. \feature. Put standard command-line options into \.{.fweb}.  Also put there
  6306. standard style parameters---e.g.,
  6307. {\codemode
  6308. +pindex.tex "#.ndx"
  6309. +pmodules.tex "#.mds"
  6310. +pcontents.tex "#.cts"
  6311. \feature. Learn how to use the style file. ^^{programming tips!style file}
  6312. \feature. Use the info options `\.{-D}', `\.{-y}', and~`\.{-Z}' 
  6313. ^^{programming tips!info options}
  6314. to find out
  6315. about various internal \FWEB\ tables (reserved words, memory allocations,
  6316. and style-file parameters).
  6317. \feature. Begin all \FWEB\ sources with invisible commentary 
  6318. ^^{programming tips!invisible commentary}
  6319. bracketed by \.{@z\dots @x}.
  6320. \feature. Always include an explicit language-setting command in the limbo
  6321. section. ^^{programming tips!language setting}
  6322. \feature. Keep sections quite short.  ^^{programming tips!section length}
  6323. Knuth suggests a dozen lines.  That's
  6324. quite hard to achieve sometimes, but almost never should a section be more
  6325. than a page long.
  6326. \feature. It's easy to  define macros from the command line to expedite
  6327. conditional preprocessing. 
  6328. ^^{programming tips!defining macros from command line} 
  6329. \feature. Use the preprocessor construction \.{@\#if 0\dots@\#endif} to
  6330. comment out unwanted code.
  6331. ^^{programming tips!commenting out code}
  6332. \feature. For logical operations with the preprocessor, use~`\.{||}',
  6333. not~`\.{|}'. 
  6334. ^^{programming tips!logical operations}
  6335. \feature. It's conventional to identify the ends of long preprocessor
  6336. constructions as follows:
  6337. {\codemode
  6338. \If\ A
  6339. \Endif\ // |A|
  6340. \feature. To debug an errant \WEB\ macro, use the built-in function
  6341. \.{\_DUMPDEF}. 
  6342. ^^{programming tips!debugging macros}
  6343. \feature. Use \atcmd{?} for compiler directives (\atcmd{!} is obsolete).
  6344. ^^{programming tips!compiler directives}
  6345. Use the style-file parameters \.{cdir\_start.$l$} to specify 
  6346. information that will be written out at the beginning of the line.
  6347. \feature. Stick to the standard \FWEB\ commenting style \.{/*\dots */} or
  6348. \.{//\dots}.  Don't use alternatives such as \Fortran's column~1
  6349. convention; these may not work or may not be supported someday.
  6350. \feature. The meta-comment feature \.{@(\dots@)} provides a poor-man's
  6351. alignment feature.  But that's not in the spirit of \TeX; learn to use
  6352. \.{\\halign} or the \LaTeX\ alternatives.
  6353. \feature. In \Fortran, use \.{\#:0} to declare readable alphabetic statement
  6354. labels.   
  6355. ^^{programming tips!alphabetic statement labels}
  6356. \feature. When mixing languages, define the language of a module at the highest
  6357. possible level---e.g., in the unamed module, not after `\.{@<\dots@>=}'.
  6358. ^^)programming tips)
  6359. ^^)usage suggestions)
  6360. \section PRESENT STATUS and the FUTURE.
  6361. The goal of \FWEB\ v.~1.0 was
  6362. to achieve functionality, particularly regarding the macro preprocessor and
  6363. \Ratfor. Having done so, it is now time to rework certain parts of the
  6364. code in order to achieve portability, optimal speed, and/or eloquence.
  6365. This will be done as time permits. Note that the author works with large
  6366. codes written with
  6367. \FWEB, so there is a powerful incentive to maintain and improve it.
  6368. The best way to ensure that \FWEB\ evolves as you would like it is to use
  6369. e-mail liberally to make suggestions, report bugs, etc.---send them to
  6370. \.{krommes@princeton.edu}.
  6371. \comment
  6372. \FWEB\ implements almost, but not all features of the new ANSI standard
  6373. for~C. ^^{language!C!ANSI standard for} For example, it understands the
  6374. names of all of the ANSI library functions, and recognizes the syntax for
  6375. function prototyping. However, it does not presently handle trigraphs (a
  6376. simple feature to add). Such deficiencies will be removed in future
  6377. versions.
  6378. Just as the C~language has stabilized with the release of the ANSI
  6379. standard, \Cpp~is arising as a significant challenger. Most of the new
  6380. features of~\Cpp\ are easy to add to \FWEB, and many already have been; a
  6381. few require nontrivial modifications. It is planned that a future release
  6382. of the \WEB\ system will fully support~\Cpp. (The command-line
  6383. option~\.{-c++} turns on knowledge of~\Cpp.)
  6384. Finally, there's \Fortran--90 on the horizon. Partial support for
  6385. \Fortran--90 is included in the present release, although this not documented.
  6386. (The command-line option~\.{-n9} tells \FWEB\ to recognize \Fortran--90 syntax.)
  6387. Although the author isn't sure that one ought to encourage the use of such
  6388. a verbose and relatively inelegant language, full support for \Fortran--90
  6389. will be provided with the next major release.
  6390. \endcomment
  6391. \vfill\eject
  6392. \section ACKNOWLEDGEMENTS. ^^(acknowledgements(
  6393. \parinserto{4}{7}{0.5}
  6394. ``Many users have
  6395. reported bugs and provided suggestions, all of which are greatly
  6396. appreciated.''
  6397. \.{FWEB} has evolved from the \.{CWEB} code
  6398. written by Silvio~Levy ^^{Levy, Silvio} of Princeton University, who
  6399. graciously provided the 
  6400. author with version~0.5 of the \.{CWEB} source code.  ^^{\>{CWEB}}
  6401. Henry Greenside ^^{Greenside, Henry}
  6402. greatly fostered the author's initial appreciation of software tools,
  6403. particularly \Ratfor.  The author is extremely grateful to Charles
  6404. Karney ^^{Karney, Charles} for providing many incisive suggestions about
  6405. \.{FWEB} and enormous help 
  6406. with all aspects of \TeX\ and computing in general. A number of
  6407. beta-testers suffered patiently 
  6408. through the initial debugging stage and made many valuable suggestions
  6409. (usually not obscene): Cris Barnes, ^^{Barnes, Cris}
  6410. John Bowman, ^^{Bowman, John} Charles
  6411. Karney, and Chang--Bae Kim. ^^{Kim, Chang--Bae}
  6412. (Patience of some of those beta-testers flagged somewhat when
  6413. \.{FWEB} stopped working a few days before a major  meeting of the American
  6414. Physical Society, but that is
  6415. perhaps understandable.) Arnold Kritz ^^{Kritz, Arnold}
  6416. generously provided both precious
  6417. time and the use of his excellent, super-enhanced IBM-PC system for
  6418. developing the original PC~version.  Barbara Kritz ^^{Kritz, Barbara}
  6419. made a seminal contribution by locating the key PC~disk on Arnold's desk.
  6420. Thorsten Ohl ^^{Ohl, Thorsten}
  6421. provided expert, trans-Atlantic
  6422. assistance and advice in debugging first the PC~version, then the ASCII
  6423. translations necessary for non-ASCII machines. Many  users have
  6424. reported bugs and provided suggestions, all of which are greatly appreciated.
  6425. Charles Karney and Bart Childs ^^{Childs, Bart}
  6426. contributed nice demos of the use of
  6427. \Fortran\ \FWEB\ (see \.{adj.web} and \.{series.web}, respectively).  
  6428. Bart Childs furnished a variety of insightful remarks about literate
  6429. programming that influenced aspects of the design of \FWEB.  Tom McCurdy
  6430. and Clarissa Wilson furnished the short pedagogical introduction
  6431. \.{Intro.tex} to \WEB\ programming that is included with the \FWEB\ release.
  6432. This work was supported by U.S. D.o.E. contract DE--AC02--76--CHO--3073. 
  6433. ^^)acknowledgements)
  6434. \section REFERENCES.
  6435. \dref{Bowman} J.~Bowman, Ph.D. thesis, Princeton University, 1992.
  6436. \dref{Knuth} D.~E. Knuth, {\sl Literate Programming} (Center for the Study
  6437. of Language and Information, Leland Standard Junior University, 1992).
  6438. \dref{KP} B.~W. Kernighan and P.~J. Plauger, {\sl Software Tools}
  6439. (Addison-Wesley, Reading, Massachusetts, 1976).
  6440. \dref{makeindex} The {\tt makeindex} utility is available from
  6441. {\tt ftp.math.utah.edu} in {\tt /pub/tex/pub/makeindex/2-11}.  The
  6442. extension~{\tt .trz} is equivalent to~{\tt .tar.Z}.
  6443. \dref{Speh} Marcus Speh, {\tt marcus@x4u.desy.de}.  For further information,
  6444. see the files in the official \FWEB\ public area:
  6445. {\tt lyman.pppl.gov:/pub/fweb/faq}.
  6446. \manrefs
  6447. \vfill\Eject
  6448. \section APPENDICES.[19.13]
  6449. \Knuth
  6450. The basic ideas of \.{WEB} can be understood most easily by looking at
  6451. examples of ``real'' programs. Appendix~A shows \[the \.{FWEB} input for the
  6452. simple \Fortran\ to \FWEB\ ^{demo program} \.{f\_to\_web}\];
  6453. Appendix~B shows the corresponding \TeX\ code output by
  6454. \.{FWEAVE}; \[Appendix~C shows excerpts from the finished woven product
  6455. typeset from \.{f\_to\_web.tex};\] and Appendix~\[D\]
  6456. shows the corresponding code output by \.{FTANGLE}.  \[Appendix~E shows the
  6457. woven output from the sample \.{f90\_cpp.web}, which mixes \Cpp\ and
  6458. \Fortran--90 code.\]
  6459. The complete webs for \.{FWEAVE} and \.{FTANGLE} \[are available in the files
  6460. \.{fweave.web} and \.{ftangle.web}. It's very instructive to study these
  6461. programs\], since \.{WEAVE} and \.{TANGLE} contain several interesting
  6462. aspects, and since an attempt has been made in these \[codes\] to evolve a
  6463. style of programming that makes good use of the \.{WEB} language.
  6464. Appendix~F is the `\.{fwebmac}' file that sets \TeX\ up to accept the
  6465. output of \.{FWEAVE}; Appendix~G discusses how to use some of its macros to
  6466. vary the output formats; \[Appendix~H summarizes how this \.{FWEB} code
  6467. differs from its immediate predecessor \.{CWEB}\].  \[Appendix~I is a
  6468. question-and-answer session about \FWEB,\] and Appendix~J discusses what
  6469. needs to be done when \.{FWEAVE} and \.{FTANGLE} are installed in a new
  6470. operating environment.
  6471. Appendix~K lists and explains the error
  6472. messages produced by \FWEB. Finally,
  6473. Appendix~L contains a summary of all the \FWEB\ syntax, commands,
  6474. and idiosyncracies.
  6475. % Here is a quotation that could not really be omitted.
  6476. \vfill
  6477. {\baselineskip9pt
  6478. \halign to\hsize{\hfil\quoteit#\tabskip 0pt plus 100pt&
  6479.   \hfil\quoteit#\tabskip 0pt\cr
  6480. O, what a tangled web we weave&
  6481.   O, what a tangled WEB we weave\cr
  6482. When first we practise to deceive!&
  6483.   When \TeX\ we practise to conceive!\cr
  6484. \noalign{\vskip 2pt}
  6485. \quoterm ---SIR WALTER SCOTT, {\quoteit Marmion} 6:17 (1808)&
  6486.   \quoterm ---RICHARD PALAIS (1982)\cr
  6487. ^^{Scott, Sir Walter} ^^{Palias, R.}
  6488. \Eject
  6489. % ------------------------------ APPENDICES ------------------------------
  6490. \appendix A: A SIMPLE DEMO PROGRAM:
  6491. {\tt f\_to\_web.web}.[{\tt f\_to\_web.web}]
  6492. ^^(\>{f\UL to\UL web}!\>{.web}(
  6493. Appendices A--D use a simple \Fortran--77 program to demonstrate the various
  6494. facets of the \WEB\ system.  The demonstration begins with the file
  6495. \.{f\_to\_web.src}, provided with the \FWEB\ distribution but not shown
  6496. here.  This appendix is a verbatim listing of a \.{web} file based on
  6497. \.{f\_to\_web.src}. Appendix~B shows the output \.{f\_to\_web.tex} from
  6498. \FWEAVE, Appendix~C 
  6499. shows part of the finished typeset product, and Appendix~D is a verbatim
  6500. listing of the output from \FTANGLE.
  6501. \HRULE
  6502. \verbatim{f_to_web.web}
  6503. ^^)\>{f\UL to\UL web}!\>{.web})
  6504. \appendix B: WOVEN OUTPUT {\tt f\_to\_web.tex}.[{\tt f\_to\_web.tex}]
  6505. The following output \.{f\_to\_web.tex} results from the command ``\.{fweave f\_to\_web}''.
  6506. \HRULE
  6507. ^^(\>{f\UL to\UL web}!\>{.tex}!raw output(
  6508. \verbatim{f_to_web.tex}
  6509. ^^)\>{f\UL to\UL web}!\>{.tex}!raw output)
  6510. \appendix C: The FINISHED PRODUCT {\tt f\_to\_web}.[FINISHED PRODUCT]
  6511. ^^(\>{f\UL to\UL web}!\>{.tex}!typeset output(
  6512. Here is part of the typeset documentation produced by saying 
  6513. ``\.{tex f\_to\_web.tex}'' and printing the output \.{f\_to\_web.dvi}.
  6514. \HRULE
  6515. \typeset{f_to_web}
  6516. \HRULE
  6517. ^^)\>{f\UL to\UL web}!\>{.tex}!typeset output)
  6518. \appendix D: TANGLED OUTPUT {\tt f\_to\_web.f}.[{\tt f\_to\_web.f}] 
  6519. The following output results from the command ``\.{ftangle f\_to\_web}''.
  6520. ^^(\>{f\UL to\UL web}!\>{.f}(
  6521. \HRULE
  6522. \verbatim{f_to_web.f}
  6523. ^^)\>{f\UL to\UL web}!\>{.f})
  6524. \appendix E: EXAMPLE of {\tt C++} and {\tt Ratfor--90} CODE.[MODERN LANGUAGES]
  6525. This example demonstrates some sample \Ratfor--90 and \Cpp~code that
  6526. involves operator overloading.  Note how the \atcmd{v}~command is used to
  6527. change the default printed form of the overloaded operators.
  6528. \HRULE
  6529. \typeset{f90_cpp}
  6530. \HRULE
  6531. \appendix F: The {\tt FWEBMAC} MACROS.[MACROS]
  6532. \iftypesetfwebmac
  6533.     \typeset{fwebmac}
  6534. \else
  6535.     If this appendix is not here, you can say \.{\\typesetfwebmactrue}
  6536. near line~39 of \.{fwebman.tex} to create a larger, self-contained manual.
  6537. Alternatively, you can weave \.{fwebmac.web} separately.
  6538. \appendix G: HOW TO USE {\tt FWEB} MACROS.[NOTES on FORMATTING][19.7.20]
  6539. The macros in \.{fwebmac.sty} (produced by tangling \.{fwebmac.web}) make
  6540. it possible to produce a variety of formats 
  6541. without editing the output of \.{FWEAVE}, and the purpose of this appendix
  6542. is to explain some of the possibilities.  \It{(NOTE:  Although \FWEB\ now
  6543. works with \LaTeX, the original discussion in this appendix was for Plain
  6544. \TeX, and it may have not been completely updated yet.)}
  6545. \endKnuth
  6546. Before proceeding, it is important to stress that it is sometimes not possible
  6547. to satisfactorily change the appearance of the woven output just by
  6548. modifying macros in \.{fwebmac}. Occasional difficulties may arise since
  6549. certain
  6550. \TeX\ commands are hard-coded into \.{FWEAVE}'s output routines. In unusual
  6551. situations, one may need to recompile \.{FWEAVE} to achieve the desired effect.
  6552. (But don't do this unless you really have to; it can be an endless sink of
  6553. time.)  However, many features can be customized via the style file.
  6554. (Please feel free to suggest additional features that should be customizable.)
  6555. \Knuth
  6556. \gdef\point#1.{\subsubsection#1.\par}
  6557. \newfeature
  6558. \point Additional fonts. \[Several\] ^{fonts} have been declared in
  6559. addition to the standard fonts of 
  6560. \.{PLAIN} format: You can say `\.{\{\\SC STUFF\}}' to get {\SC STUFF}
  6561. in small caps, \[or `\.{\{\\Csc Stuff\}}' to get {\Csc Stuff}\]; 
  6562. ^^:\CS{SC}: ^^:\CS{Csc}: ^^:fonts!small caps\actual{\SC SMALL CAPS}:
  6563. ^^:fonts!caps/small caps\actual{\Csc CAPS/small caps}: 
  6564. and you can select the largish fonts \.{\\titlefont} and \.{\\ttitlefont}
  6565. in the title of your document, where \.{\\titlefont} ^^:\CS{titlefont}:
  6566. gives one {\titlefont titlefont} and \.{\\ttitlefont} ^^:\CS{ttitlefont}:
  6567. is a typewriter style of type giving one {\ttitlefont ttitlefont}.
  6568. \point Typesetting comments. Comments are typeset in the font
  6569. \.{\\cmntfont}, ^^:\CS{cmntfont}: ^^:fonts!comment:
  6570. which is \.{\\let} to \.{\\tenrm} ^^{\CS{tenrm}}
  6571. by default.  You can redefine \.{\\cmntfont} in the
  6572. limbo section;  ^^{limbo!section}
  6573. for example, ``\.{\\let\\cmntfont\\Csc}''.
  6574. \point Typesetting identifiers. ^^[identifiers!typesetting]
  6575. When you mention an identifier in \TeX\
  6576. text, you normally call it `\.{|identifier|}'. But \[if that identifier is
  6577. not a 
  6578. reserved word\], you can also say `\.{\\\\\{identifier\}}'.  ^^:\CS{\BS}:
  6579. The output will look the same in both cases, \[namely `\\{identifier}'\],
  6580. but the second alternative doesn't put \\{identifier} into the index, since
  6581. it bypasses \.{WEAVE}'s translation from \[code\] mode. \[For one-character
  6582. identifiers, you should say `\.{\\|i}' to get `\\i'. ^^:\CS{"|}: Also, for
  6583. a reserved 
  6584. word you can say `\.{\\\&\{reserved\}}' to get `\&{reserved}'. ^^:\CS{\amp}:
  6585. If you're
  6586. talking about an intrinsic function, you can say '\.{\\@@\{intrinsic\}}' to
  6587. get `\IF{intrinsic}'. ^^:\CS{@}: (Note that the macro name itself is
  6588. `\.{\\@}'.)\] 
  6589. Note that \WEB\ identifiers may contain the characters~`\.\$' and~`\.\_'.
  6590. These must be preceded by a backslash when using them with the
  6591. macros~\.{\\\\},
  6592. \.{\\\&}, and~\.{\\@}.  This is not necessary when enclosing such
  6593. identifiers between vertical bars; \WEB\ handles the escaping for you.
  6594. Thus, say ``\.{|id\_code|}'' but ``\.{\\\\\{id\\\_code\}}''.
  6595. ^^{LaTeX:\LATEX}
  6596. \LaTeX\ users (see the section below on Using \LaTeX)
  6597. will object that `\.{\\\\}'~means something very different to
  6598. them.  Actually, the true situation is slightly more complicated than that
  6599. described in the last paragraph.  In \.{fwebmac}, the macro that
  6600. formats an ordinary identifier is really called~`\.{\\Wid}', ^^:\CS{Wid}:
  6601. not~`\.{\\\\}'.
  6602. The macro~`\.{\\\\}' becomes associated with~`\.{\\Wid}' because the
  6603. style-file entry `\.{format.identifier}' has~`\.{\\\\}' as its default
  6604. value.  That value is transmitted to \TeX\ or \LaTeX\ via the
  6605. `\.{\\Wbegin}' macro ^^:\CS{Wbegin}:
  6606. that is emitted automatically just after the ``\.{\\input fwebmac.sty}''
  6607. command at the beginning of the output file.  (Study a sample of woven
  6608. output, for example Appendix~B.)  Similar equivalences are set up for the
  6609. other formatting macros according to the following table:
  6610. \input equiv
  6611. ^^:\CS{Wreserved}:  ^^:\CS{Wshort}:  ^^:\CS{Wid}:  ^^:\CS{WidD}:
  6612. ^^:\CS{WidM}: ^^:\CS{Wintrinsic}:  ^^:\CS{Wkeyword}:  
  6613. Note that by default macro names are treated the same way as ordinary
  6614. identifiers.  To cause macro names to be formatted in a distinctive way,
  6615. you must use the style-file entries \.{format.outer\_macro} and/or
  6616. \.{format.WEB\_macro}. 
  6617. ^^{macro!outer!formatting} ^^{macro!inner!formatting}
  6618. (If more than one of these has the same value, the equivalences to the
  6619. fundamental definitions in \.{fwebmac.sty} are made in the order
  6620. \.{format.WEB\_macro}, \.{format.outer\_macro}, then \.{format.identifier}.)
  6621. However, you must \It{also} supply a new definition
  6622. for the \.{fwebmac} macros~\.{\\WidD} and/or~\.{\\WidM}, 
  6623. ^^{\CS{WidD}} ^^{\CS{WidM}}
  6624. since by default
  6625. these are merely \.{\\let} equal to~\.{\\Wid}.  You could introduce such
  6626. new definitions by placing them into a file that is \.{\\input}
  6627. automatically at the beginning of each run (see the style-file entry
  6628. \.{limbo}), ^^{style file!vocabulary!\>{limbo}}
  6629. by creating a new personal version of \.{fwebmac.sty}
  6630. ^^{\>{fwebmac}!\>{.sty}!personal version of}
  6631. (use a change file in conjunction with \.{fwebmac.web}), or by using the
  6632. \atcmd{l}~command ^^{\>{@l}}
  6633. to place the definition directly into the limbo section of your code.
  6634. \point Typewriter type.  ^^[fonts!\>{typewriter}]
  6635. To get typewriter-like type, as when referring to
  6636. `\.{WEB}', you 
  6637. can use the `\.{\\.}' macro (e.g., `\.{\\.\{FWEB\}}'). ^^{\CS.}
  6638. In the argument to
  6639. this macro you should insert an additional backslash before the \[following
  6640. characters enclosed by double quotes: ``\.{\ \\\#\%\$\^\{\}\~\&\_}''\].
  6641. A `\.{\\\ }' here will result in the visible space ^^{space!visible}
  6642. symbol; to get an invisible space ^^{space!invisible}
  6643. following a control sequence you can say `\.{\{\ \}}'.
  6644. \endKnuth
  6645. The original form of the `\.{\\.}' macro surrounded the string with an
  6646. \.{\\hbox}, which unfortunately
  6647. prevented very long strings from being broken across lines. The present
  6648. \FWEB\ form does \It{not} surround the string with an \.{\\hbox} and allows
  6649. strings to be broken, either after commas or every so many characters. To
  6650. accomplish this, \FWEAVE\ inserts into strings special control sequences
  6651. that are treated essentially like discretionary hyphens. Automatically
  6652. broken strings are marked by a backslash at the end of the line.
  6653. Actually, the \.{fwebmac} macro for typewriter type is called
  6654. `\.{\\Wtypewriter}'.  ^^:\CS{Wtypewriter}:  ^^{style
  6655.     file!vocabulary!\>{format.typewriter}} 
  6656. Its equivalence to~`\.{\\.}' is established by the
  6657. same mechanism as described above for formatting identifiers, via the
  6658. style-file entry `\.{format.typewriter}'. 
  6659. \Knuth
  6660. \point Page dimensions.  ^^[page!dimensions]
  6661. The three control sequences \.{\\pagewidth}, \.{\\pageheight}, 
  6662. and \.{\\fullpageheight} 
  6663. ^^:\CS{pagewidth}: ^^:\CS{pageheight}: ^^:\CS{fullpageheight}:
  6664. can be redefined in the limbo section ^^{limbo!section}
  6665. at the 
  6666. beginning of your \.{WEB} file to change the dimensions of each page.
  6667. The standard settings
  6668. $$\lpile{\.{\\pagewidth=6.5in}\cr
  6669.   \.{\\pageheight=8.7in}\cr
  6670.   \.{\\fullpageheight=9in}\cr}$$
  6671. were used to prepare the present report; \.{\\fullpageheight} is
  6672. \.{\\pageheight} plus room for the additional heading and page numbers at
  6673. the top of each page. If you change any of these quantities, you should
  6674. call the macro \.{\\setpage} immediately after making the change.
  6675. \point Page heads. ^^[page!heads] ^^:\CS{identicalpageheads}:
  6676. The macro \.{\\identicalpageheads} is normally false, which means that by
  6677. default the page numbers and module numbers will alternate left and right
  6678. on even- and odd-numbered pages.  If you want all the page heads to be
  6679. formatted identically, say ``\.{\\identicalpageheadstrue}''.
  6680. \point Shifting pages left or right. ^^[page!shifting] ^^:\CS{pageshift}:
  6681. The \.{\\pageshift} macro defines an amount by which right-hand
  6682. pages (i.e., odd-numbered pages) are shifted right with respect to
  6683. left-hand (even-numbered) ones. By adjusting this amount you may be
  6684. able to get two-sided output in which the page numbers line up on
  6685. opposite sides of each sheet.
  6686. \point Page title. ^^[page!title] ^^[title] ^^:\CS{Wtitle}:
  6687. The \.{\\Wtitle} macro will appear at the top of each page
  6688. in small caps.   This macro is null by default, but you can define it in
  6689. the limbo section.
  6690. \comment
  6691. For example, Appendix~D was produced after saying
  6692. `\.{\\def\\Wtitle\{WEAVE\}}'.
  6693. \endcomment
  6694. \point Page numbering. ^^[page!numbering] ^^{\CS{pageno}}
  6695. The first page usually is number 1; if you want some other
  6696. starting page, just set \.{\\pageno} to the desired number---e.g.,
  6697. `\.{\\pageno=16}'.
  6698. \endKnuth
  6699. \point Paragraph breaks.  ^^[paragraph breaks] 
  6700. By default, paragraph breaks in \TeX\ mode are spaced out with an
  6701. extra blank line. If you don't want that, say `\.{\\pardimen=0pt}'.
  6702. ^^:\CS{pardimen}:
  6703. \point Magnifying the output. ^^[output, magnifying] ^^[page!magnification]
  6704. ^^:\CS{magnify}: 
  6705. If you want your output to be bigger than usual, use 
  6706. \.{\\magnify} instead of  \.{\\magnification}; say, for example,
  6707. `\.{\\magnify\{\\magstep1\}}'. 
  6708. \Knuth
  6709. \point Table of contents. ^^[table of contents]
  6710. ^^{\CS{iftitle}} ^^:\CS{titletrue}: ^^:\CS{titlefalse}: 
  6711. The macro \.{\\iftitle} will suppress the header line if it is defined by
  6712. `\.{\\titletrue}'. The normal value is \.{\\titlefalse} except for the
  6713. table of contents; thus, the contents page is usually unnumbered. If your
  6714. program is so long that the table of contents doesn't fit on a single page,
  6715. or if you want a number to appear on the contents page, you should reset
  6716. \.{\\pageno} when you begin the table of contents.
  6717. ^^:\CS{topofcontents}: ^^:\CS{botofcontents}:
  6718. Two macros are provided to give flexibility to the table of
  6719. contents: \.{\\topofcontents} is invoked just before the contents
  6720. info is read, and \.{\\botofcontents} is invoked just after.
  6721. For example, Appendix~D of Knuth's original manual was produced with the
  6722. following definitions: 
  6723. $$\lpile{\.{\\def\\topofcontents\{\\null\\vfill}\cr
  6724.   \.{ { }\\titlefalse \% include headline on the contents page}\cr
  6725.   \.{ { }\\def\\rheader\{\\mainfont Appendix D\\hfil 15\}}\cr
  6726.   \.{ { }\\centerline\{\\titlefont The \{\\ttitlefont WEAVE\}{ }processor\}}\cr
  6727.   \.{ { }\\vskip 15pt \\centerline\{(Version 2.5)\}{ }\\vfill\}}\cr}$$
  6728. Redefining \.{\\rheader}, which is the headline for right-hand pages,
  6729. suffices in this case to put the desired information at the top of the page.
  6730. \point Customizing the table of contents. ^^[table of contents!customizing]
  6731. ^^:\>{CONTENTS.tex}: 
  6732. Data for the ^{table of contents} is written to a file that
  6733. is read after the indexes have been \TeX ed; there's one line of data
  6734. for every starred module. For example, one might obtain
  6735. a file \.{CONTENTS.tex} ^^{\>{CONTENTS.tex}}
  6736. containing
  6737. $$\lpile{\.{\\WZ \{0\}\{{ }Introduction\}\{1\}\{16\}}\cr
  6738.   \.{\\WZ \{0\}\{{ }The character set\}\{11\}\{19\}}\cr}$$
  6739. and similar lines. Here the first argument of~\.{\\WZ} ^^:\CS{WZ}:
  6740. is the level number of the
  6741. module, the second argument is the title, the third is the module number,
  6742. and the fourth is the page number.
  6743. The \.{\\topofcontents} macro ^^{\CS{topofcontents}}
  6744. could redefine \.{\\WZ} so that the information appears in another format.
  6745. (The default name \.{CONTENTS.tex} can be changed by means of the
  6746. style-file parameter ``\.{contents.tex}''.
  6747. ^^{style file!vocabulary!\>{contents.tex}}
  6748. \point Date and time. ^^[date] ^^[time] ^^:\CS{Date}: ^^:\CS{Time}:
  6749. The macro \.{\\Date} gives the present date in the form ``\Date''.
  6750. The macro \.{\\Time} gives the time in the form ``\Time''. By default,
  6751. these are printed automatically at the bottom of the title page, via the
  6752. \.{\\botofcontents} macro.
  6753. \point Subdividing output. ^^[output!subdividing]
  6754. Sometimes it is necessary or desirable to divide the output of
  6755. \.{WEAVE} into subfiles that can be processed separately. For example,
  6756. the listing of \TeX\ runs to more than 500 pages, and that is enough to
  6757. exceed the capacity of many printing devices and/or their software.
  6758. When an extremely large job isn't cut into smaller pieces, the entire
  6759. process might be spoiled by a single error of some sort, making it
  6760. necessary to start everything over.
  6761. Here's a safe way to break a woven file into three parts:
  6762. Say the pieces are $\alpha$,
  6763. $\beta$, and $\gamma$, where each piece begins with a starred module.
  6764. All macros should be defined in the opening limbo section ^^{limbo!section}
  6765. of $\alpha$,
  6766. and copies of this \TeX\ code should be placed at the
  6767. beginning of $\beta$ and of $\gamma$. In order to process the parts
  6768. separately, we need to take care of two things: The starting page
  6769. numbers of $\beta$ and $\gamma$ need to be set up properly, and
  6770. the table of contents data from all three runs needs to be
  6771. accumulated.
  6772. ^^:\CS{contentsfile}: ^^:\CS{readcontents}:
  6773. The \.{webmac} macros include two control sequences \.{\\contentsfile} and
  6774. \.{\\readcontents} that facilitate the necessary processing.  We include
  6775. `\.{\\def\\contentsfile\{CONT1\}}' in the limbo section of $\alpha$, and
  6776. we include `\.{\\def\\contentsfile\{CONT2\}}' in the limbo section of
  6777. $\beta$; this causes \TeX\ to write the contents data for $\alpha$ and $\beta$
  6778. into \.{CONT1.TEX} and \.{CONT2.TEX}. Now in $\gamma$ we say
  6779. $$\hbox{\.{\\def\\readcontents\{\\input CONT1 \\input CONT2 \\input
  6780. CONTENTS\}}};$$ 
  6781. this brings in the data from all three pieces, in the proper order.
  6782. However, we still need to solve the page-numbering problem. One way to
  6783. do it is to include the following in the limbo material for $\beta$:
  6784. $$\lpile{\.{\\message\{Please type the last page number of part 1: \}}\cr
  6785.   \.{\\read-1to\\\\ \\pageno=\\\\ \\advance\\pageno by 1}\cr}$$
  6786. Then you simply provide the necessary data when \TeX\ requests
  6787. it; a similar construction is used at the beginning of $\gamma$.
  6788. This method can, of course, be used to divide a woven file into
  6789. any number of pieces. \[(One problem with it is that each piece will have its
  6790. own index. This problem will be addressed in the future.)\]
  6791. \point Special index entries.  ^^[index!entry]
  6792. Sometimes it is nice to include things in the index that are
  6793. typeset in a special way. For example, we might want to have an
  6794. index entry for `\TeX'. \.{WEAVE} provides only two standard ways to
  6795. typeset an index entry (unless the entry is an identifier, an intrinsic
  6796. function, or a reserved word): 
  6797. \atcmd{\^}~gives roman type, and \atcmd{.}~gives \.{typewriter} type.
  6798. But if we try to typeset `\TeX' in roman type by saying, e.g.,
  6799. \atcmd{\^\\TeX@>}, the backslash character gets in the way,
  6800. and this entry wouldn't appear in the index with the T's.
  6801. The solution is to use the \atcmd{9}~feature,  ^^{\>{@9}} ^^{\CS9}
  6802. declaring a macro that
  6803. simply removes a sort key as follows:
  6804. $$\hbox{\.{\\def\\9\#1\{\}}}$$
  6805. Now you can say, e.g., \atcmd{9TeX\}\{\\TeX@>} in your \.{WEB} file; \.{WEAVE}
  6806. puts it into the index alphabetically, based on the sort key, and
  6807. produces the macro call `\.{\\9\{TeX\}\{\\TeX\}}' which will ensure that
  6808. the sort key isn't printed.
  6809. A similar idea can be used to insert hidden material into module
  6810. names so that they are alphabetized in whatever way you might wish.
  6811. Some people call these tricks ``special refinements''; others call
  6812. them ``kludges''. ^^:kludges: ^^:refinements, special:
  6813. \point Module number. ^^:\CS{modno}:
  6814. The control sequence \.{\\modno} is set to the number of the
  6815. module being typeset. 
  6816. \endKnuth
  6817. \point Symbolic names of modules. ^^[modules!symbolic names of]
  6818. ^^:\CS{modlabel}: ^^:\CS{module}: ^^:\CS{WEBmodule}: ^^:\CS{WEBsection}:
  6819. The macros \.{\\modlabel} and \.{\\module} afford a way of assigning
  6820. symbolic names to modules (whose absolute numbers one doesn't know). Say
  6821. \.{\\modlabel\{alpha\}} somewhere in the module in question. If somewhere else
  6822. you want to discuss that particular module, say something like
  6823. `\.{discussed in \\module\{alpha\}}'. With Plain \TeX,
  6824. forward references do not work; you
  6825. must label the module before you reference it with \.{\\module}.  (However,
  6826. the scheme could be generalized in standard ways, using the I/O features of
  6827. \TeX.)  When \LaTeX\ is in use, ^^{LaTeX:\LATEX}
  6828. forward references \It{do} work; the
  6829. definitions of the module labels are stored in the \.{.aux} file, ^^{\>{.aux}}
  6830. using \LaTeX's \.{\\label} macro.  ^^{\CS{label}}
  6831. In fact, under \LaTeX\ the definitions of \.{\\modlabel} and \.{\\module}
  6832. are equivalent to simply 
  6833. \begintt
  6834. \def\modlabel#1{\label{MOD#1}}
  6835. \def\module#1{module~\ref{MOD#1}}
  6836. \endtt
  6837. If you want to say ``section'' instead of ``module'', say
  6838. ``\.{\\WEBsection}'' instead of ``\.{\\module}''.  (\LaTeX\ usurps
  6839. ``\.{\\section}''.) For symmetry, ``\.{\\WEBmodule}'' is equivalent to
  6840. ``\.{\\module}''. 
  6841. \Knuth
  6842. \point Listing modules that have been changed. ^^[modules!listing changed]
  6843. ^^:\CS{maybe}:
  6844. If you want to list only the modules that have changed,
  6845. together with the index, put the command `\.{\\let\\maybe=\\iffalse}' in
  6846. the limbo section before the first module of your \.{WEB} file. It's
  6847. customary to make this the first change in your change file.
  6848. \endKnuth
  6849. \point Loading the macro package. ^^[\>{fwebmac}!\>{.sty}!loading]
  6850. ^^:\CS{ifWEB}: ^^:\CS{ifFWEB}: ^^:\CS{WEBisloaded}: ^^:\CS{FWEBisloaded}: 
  6851. The macro package \.{fwebmac.sty} \.{\\let}s~the macro
  6852. \.{\\FWEBisloaded} to be \.{\\relax}. This macro
  6853. can be used in various ways by macros you write that may need to behave
  6854. differently depending on whether \.{fwebmac} has been loaded or not. See
  6855. the Dirty Tricks section of the \TeX book.
  6856. \point Redefined macros.
  6857. The macro package \.{fwebmac} usurps certain macro names for its own
  6858. use.  To find a complete list of the \.{fwebmac} macros, look in the index
  6859. to \.{fwebmac.tex}.  The original definitions of some of the more common
  6860. ones are stored away under other names, as follows:
  6861. ^^:\CS{amp}: ^^{\CS{\amp}}
  6862. ^^:\CS{at}:  ^^{\CS{@}}
  6863. ^^:\CS{bslash}: ^^{\CS{\BS}}
  6864. ^^:\CS{caret}: ^^{\CS{\^}}
  6865. ^^:\CS{dollar}: ^^{\CS{\dollar}}
  6866. ^^:\CS{dstar}: ^^{\CS{*}}
  6867. ^^:\CS{equals}: ^^{\CS{=}}
  6868. ^^:\CS{leftbrace}: ^^{\CS{\LB}}
  6869. ^^:\CS{period}: ^^{\CS.}
  6870. ^^:\CS{rightbrace}: ^^{\CS{\RB}}
  6871. ^^:\CS{vertbar}: ^^{\CS{"|}}
  6872. ^^:\CS{PM}: ^^{\CS{\PM}}
  6873. ^^:\CS{PC}: ^^{\CS{\PC}}
  6874. \begintt
  6875. \let\amp\&
  6876. \let\at\@
  6877. \let\bslash\\
  6878. \let\caret\^
  6879. \let\dollar\$
  6880. \let\dstar\*
  6881. \let\equals\=
  6882. \let\leftbrace\{
  6883. \let\period\.
  6884. \let\rightbrace\}
  6885. \let\vertbar|
  6886. \let\PM\#
  6887. \let\PC\%
  6888. \endtt
  6889. \point Using {\tt FWEB} with \LaTeX. ^^[LaTeX:\LATEX]
  6890. The \WEB\ system was originally designed for use with Plain \TeX, and the
  6891. design of the macros in \.{fwebmac} reflects this.  However, with some
  6892. restrictions it is 
  6893. also possible to use \FWEB\ with \LaTeX, thereby gaining the use of
  6894. additional convenient macros, environments, etc.  To use \LaTeX\ instead of
  6895. \TeX\ to process the output \.{test.tex} that results from running \FWEAVE\
  6896. on \.{test.web}, you should do two things at a minimum:  
  6897. {\narrower
  6898. \item{(1)} Use the command-line option `\.{-PL}'.  ^^{\={-p}{-P}}
  6899. ^^{\TeX\ processor, selecting}
  6900. (If you will always be using \LaTeX, place the command `\.{+PL}' into your
  6901. \.{.fweb} file.) ^^{\>{.fweb}}
  6902. This command affects the default definitions of certain quantities defined
  6903. through the style file; see the discussion below.
  6904. \item{(2)} Simply say ``\.{latex test}'' instead of ``\.{tex test}''.
  6905. \parinsert{4}{4}{0.4}
  6906. Just say ``{\ssbf latex test}'' instead of ``{\ssbf tex test}''.
  6907. Probably the principal
  6908. price one pays is that \FWEB\ has already usurped certain macro names for
  6909. its own use.  For example, the standard \FWEB\ macro used to format an ordinary
  6910. identifier is~`\.{\\\\}'. See the table just above for alternative macro
  6911. names.  For example, a \LaTeX\ user could use `\.{\\bslash}' instead
  6912. of~`\.{\\\\}'.  
  6913. However, since the use of~`\.{\\\\}' is quite common in \LaTeX\ and
  6914. it is cumbersome to type `\.{\\bslash}' 
  6915. it is possible to dynamically reconfigure \FWEAVE\ to use a
  6916. different macro to format ordinary identifiers.  This is done through the
  6917. style file.  As explained above in the section on ``Typesetting
  6918. identifiers,'' the names of the identifiers actually used in the \.{tex}
  6919. file to format identifiers are mapped through an equivalencing procedure to
  6920. the actual definitions in \.{fwebmac}, and those names can be changed
  6921. without tampering with the definitions through entries in the style file.
  6922. If no entries are made in the style file, then by default the
  6923. macro~`\.{\\\\}' is used to format both outer macro names, \WEB\ macro
  6924. names, and ordinary identifiers (with more than one character).  When the
  6925. `\.{-PL}'~option is used, then that default is instead chosen to
  6926. be~`\.{\\>}'.  That default can be overridden by explicit style-file entries.
  6927. Additional difficulties will arise with certain attempts to produce very clever
  6928. output using some of the page layout facilities of \LaTeX, since \FWEB\
  6929. overrides the \.{\\output} ^^{\CS{output}}
  6930. routine of \LaTeX.  
  6931. Also, \LaTeX's \.{\\index} macro ^^{\CS{index}}
  6932. is not correlated in any way to the index produced by \FWEAVE.
  6933. On the positive side, the use of the \.{aux} ^^{\>{.aux}}
  6934. file allows forward referencing to module names to be done conveniently.
  6935. In particular, \LaTeX's \.{\\label} macro ^^{\CS{label}}
  6936. understands the current module
  6937. number.  (It does \It{not} understand anything about the level of starred
  6938. modules.) See the discussion about ``Symbolic names of modules'' above.
  6939. Beginning with version~1.30 the \.{fwebmac} macros have been augmented
  6940. (thanks to Charles Karney) ^^{Karney, Charles}
  6941. to work with \LaTeX's New Font Selection Scheme (NFSS).  
  6942. ^^{NFSS} ^^{fonts!selecting}
  6943. There hasn't been too much experience here; please report any difficulties.
  6944. \appendix H: SUMMARY of EXTENSIONS or CHANGES FROM {\tt CWEB}.[CHANGES FROM
  6945. {\tt CWEB}]
  6946. \It{Here are some of the more significant differences between \CWEB\ and
  6947. \FWEB~1.0. Many more features have been added in v.~1.1 and later;
  6948. these are too numerous to describe here.}
  6949. Blank lines in the source are significant to \WEAVE. The \atcmd{\#}~command
  6950. will hardly ever have to be used. 
  6951. The unnamed module is begun by~\atcmd{a}.
  6952. Language switching: the \atcmd{c}, \atcmd{r}, and \atcmd{n}~commands.
  6953. Long strings (`\.{\\.}' macro)
  6954. are broken with discretionary backslashes every so many characters, 
  6955. and after commas.
  6956. Verbatim comments: Preface comments you want \TANGLE\ to keep by~\atcmd{},
  6957. as in `\atcmd{/*\ Keep.\ */}'.
  6958. Make all comments verbatim by command-line option~`\.{-v}'.
  6959. \WEB\ macros, defined by \atcmd{m} and expanded by \TANGLE, were reintroduced.
  6960. Macro definitions are allowed in the code section.
  6961. A \C-like preprocessing language was added. The preprocessor commands may
  6962. appear in either the definition section or the code section. 
  6963. \FTANGLE\ translates \Ratfor\ directly to \Fortran.
  6964. One-character uppercase \.{fwebmac} macros have been changed to
  6965. two-character ones starting with~`\.{W}'.
  6966. Because physicists sometimes like to use the asterisk for complex
  6967. conjugation and therefore may define it to be an active character, \FTANGLE\
  6968. will output an asterisk when it is in \TeX\ mode, but puts out
  6969. ``\.{\\ast}'' when it is in code mode. 
  6970. \appendix I:  \FWEB\ Q and A.[Q and A] ^^[questions] ^^[answers]
  6971. \def\Q#1\par{\noindent{\bf Q.\enspace}{\it\ignorespaces#1}\par}
  6972. \def\A#1\par{{\narrower\noindent\hang{\bf A.\enspace}\ignorespaces#1\par}}
  6973. \It{This section is not complete!} Please see \.{/pub/fweb/faq} for a more
  6974. complete discussion\cite{Speh}.
  6975. \Q What is the difference between \.{fwebmac.web}, \.{fwebmac.tex}, and
  6976. \.{fwebmac.sty}? 
  6977. ^^{\>{fwebmac}!\>{.web}} ^^{\>{fwebmac}!\>{.tex}} ^^{\>{fwebmac}!\>{.sty}} 
  6978. \A The macros read in by the \.{*.tex} files produced by \FWEAVE\ are
  6979. called \.{fwebmac.sty}; they are maintained in the source file
  6980. \.{fwebmac.web}.  Running \FTANGLE\ on \.{fwebmac.web} produces
  6981. \.{fwebmac.sty}; if you want to see a pretty listing of the macros, run
  6982. \FWEAVE\ on the source to get \.{fwebmac.tex}.
  6983. \Q Why not incorporate Pascal ^^{language!Pascal}
  6984. as one of the supported languages, especially
  6985. since Knuth's original processors supported that?
  6986. \A This project evolved from Levy's \CWEB, which was written in~C for~C.
  6987. Since the present author does not personally use Pascal, it was considered
  6988. too much of an effort to incorporate Pascal processing, especially since
  6989. most modern codes are written in~C.
  6990. \Q What is the difference between \.{.fweb} and \.{fweb.sty}?
  6991. ^^{\>{.fweb}} ^^{\>{fweb.sty}}
  6992. \A Both are initialization files.  However, \.{.fweb} is intended to be
  6993. a global initialization file for all runs made by a particular author.  One
  6994. is supposed to put common command-line options into here.  The style file
  6995. \.{fweb.sty} is intended to allow customizations of particular runs or
  6996. groups of runs.  For example, the appearance of the index can be customized
  6997. by setting parameters in the style file.  Also, \.{.fweb}~is read
  6998. \It{before} the command line is processed, while \.{fweb.sty}~is read
  6999. \It{after} \.{.fweb} and the command-line are processed.
  7000. \Q How does one force \FWEAVE\ to align comments?
  7001. ^^{comments!aligning}
  7002. \A One can't do that yet.  In general, all complicated alignment issues
  7003. relating to \FWEAVE\ have been deferred to a future version.  Sorry!
  7004. \It{This list is not completed yet. Please suggest questions to be
  7005. discussed in this space.} 
  7006. \appendix J: ERROR MESSAGES.[][19.11.5]
  7007. ^^(error messages(
  7008. \def\errorclass#1\par{\subsubsection #1\par}
  7009. %\bigskip\leftline{\bf #1:}\nobreak}
  7010. \def\error#1#2\par{\noindent\hang{\bf ``#1.''}\enspace\ignorespaces#2\par}
  7011. \parskip=\pardimen
  7012. Presently the error- message-processing facilities are a mixture of old and
  7013. new: the original scheme of Knuth and Levy was restricted to function calls
  7014. with fixed 
  7015. number of arguments, which tended to result in error messages with the bare
  7016. minimum of information. Many, although not yet all, of the error messages have
  7017. now been generalized to calls allowing variable numbers of arguments, which
  7018. facilitates constructing rather elaborate error messages. Error processing
  7019. will be refined still further in the future. \It{It is very important that
  7020. you report difficulties with \FWEB's error processing facilities.} If
  7021. \FWEB\ ever issues an error not in the following list, please report that too.
  7022. There are five general classes of error messages: (1)~messages common to
  7023. both \FTANGLE\ and \FWEAVE\ (produced, for example, by command-line
  7024. processing or one of the input drivers); 
  7025. (2)~general
  7026. messages from \FTANGLE; (3)~macro processing errors; (4)~\Ratfor\ errors;
  7027. (5)~general messages from \FWEAVE.  The class of the error is (usually)
  7028. indicated in the output to the screen.
  7029. There is as yet no numbering scheme. The
  7030. messages are described here alphabetically within each class. Italics
  7031. indicate variable fields that are filled in by the particular situation.
  7032. \errorclass Messages common to both {\tt FTANGLE} and {\tt FWEAVE}.
  7033. ^^(error messages!common to both processors(
  7034. \error{Ambiguous prefix} A section name abbreviated with an ellipsis was
  7035. not unique.
  7036. \error{Can't open include file \."\It{name}\."} Possibly a misspelled file
  7037. name; the \.{@i} command is skipped.
  7038. \error{\.{get\_mem0}:  Can't request $n$~units; used max of~$n$}
  7039. Either you're asking for too much memory, or there's something wrong with
  7040. the use of the ANSI \\{calloc} routine.  If you think it's the latter,
  7041. please report it.
  7042. \error{Change file ended after \.{@x}} There's something missing.
  7043. \error{Change file ended before \.{@y}} You must use the complete
  7044. construction \.{@x}\dots\.{@y}\dots\.{@z}.
  7045. \error{Change file ended without \.{@z}} You must  use the complete
  7046. construction \.{@x}\dots\.{@y}\dots\.{@z}.
  7047. \error{Change file entry did not match} There's no text in the \WEB\ file
  7048. that matches the stuff between~\.{@x} and~\.{@y}.
  7049. \error{\.{get\_mem0}: Can't request $n$~units; used max of $m$} This is
  7050. probably related to the difference between \&{int}s and \&{long}s on the local
  7051. machine, and may signify a bug in the implementation.
  7052. \error{Hmm\dots\ some of the preceding lines failed to match} There was
  7053. stuff left in the change buffer at the end of the run.
  7054. \error{\.{get\_mem0}: Can't request $n$~units; used max of $m$} This is
  7055. probably related to the difference between \&{int}s and \&{long}s on the local
  7056. machine, and may signify a bug in the implementation.
  7057. \error{Hmm\dots\ some of the preceding lines failed to match} There was
  7058. stuff left in the change buffer at the end of the run.
  7059. \error{Input line too long; must be shorter than \It{n} characters} The
  7060. input line length may be increased with the \.{-mbs} option.
  7061. \error{Invalid 'g' option: parameter type $c$}.  The valid parameters
  7062. are~'\.r', '\.m', or~'\.s'.
  7063. \error{Invalid 'g' option: \dots} You specified an invalid parameter for the
  7064. \Ratfor\ \&{switch}.
  7065. \error{Invalid language command "\dots"} You said \atcmd{L$l$}, where
  7066. $l$~was not one of~'\.c', '\.n', '\.r', or~'\.x'.
  7067. \error{Missing id for \.{'m'} option} To define a macro from the command
  7068. line, you must say \.{-mA=1} or \.{-m"A\ 1"}.
  7069. \error{Missing id for \.{'u'} option} You must say \.{-u\It{name}}.
  7070. \error{Missing language character after~\.{@L}} You must say~\atcmd{L$l$}.
  7071. \error{No includes allowed in change file} You may not use the \.{@i}
  7072. command within a change file.
  7073. \error{Style file name too long; must be less than $n$~characters} There's
  7074. something wrong with the \.{-z} option.
  7075. \error{Syntax error in output redirection command \.{"->"}. Language must
  7076. be one of \.{'c'}, \.{'r'}, or \.{'n'}, not \.{'$x$'}} If you're
  7077. redirecting output from a particular language, the form of the command is
  7078. ``\.{->$l$=\It{file}}''.
  7079. \error{Too many nested includes; $n$~allowed} \.{@i}~commands can be nested
  7080. to a level of~$n$.
  7081. \error{WARNING: Command-line language \It{name} overridden in limbo by
  7082. \It{new\_name}} A language command in the limbo section always takes
  7083. precedence over a language specified on the command line.
  7084. \error{WEB file ended during a change} There's something incompatible about
  7085. the change you're trying to make.
  7086. \error{Where is the matching \.{@x}?} In the change file, a~\.{@y}
  7087. or~\.{@z} was encountered before an \.{@x}.
  7088. \error{Where is the matching \.{@y}?} A misplaced \.{@x} or~\.{@z} was
  7089. encountered. 
  7090. \error{Where is the matching \.{@z}?} A misplaced \.{@x} or~\.{@y} was
  7091. encountered. 
  7092. ^^)error messages!common to both processors)
  7093. \errorclass General messages from {\tt FTANGLE}.
  7094. ^^(error messages!\>{FTANGLE}(
  7095. \error{@d, @f, and @a are ignored in code text} \.{@d} and~\.{@f} may
  7096. appear only in the definition section. \.{@a}, which signifies the unnamed
  7097. module, must be preceded by either \.{@\ } or \.{@*}.
  7098. \error{ASCII string didn't end} ASCII constants such as \.{@'a'} must end
  7099. on the same input line as they begin. (They can't even be continued by
  7100. backslashes.)
  7101. \error{Can't continue comments on \.{@i}~lines} You said something like
  7102. `\atcmd{i\ \It{filename}\ /*\dots}'.
  7103. \error{Code text flushed; \.= sign is missing} A section name of the form
  7104. \.{@<\dots@>} was encountered at the end of a \TeX\ or definition section,
  7105. but it wasn't followed by the requisite equals sign that signifies the
  7106. start of a named module.
  7107. \error{Compiler directives are allowed only in code} The compiler directive
  7108. command~\.{@!} was encountered while scanning through \TeX\ text.  This
  7109. directive is allowed only in the code section.
  7110. \error{Continuation character \.{'$c$'} from \.{'\&'} option is invalid;
  7111. \.{'$d$'} assumed} \Fortran's continuation character must be printable and
  7112. not blank. 
  7113. \error{Definition flushed; must start with identifier} An \.{@d} or~\.{@m}
  7114. command must be followed by a valid identifier.
  7115. \error{Expected \.{@>} after \.{@<}} A section name must be indicated by
  7116. \.{@<\dots@>}. 
  7117. \error{Expected '$c$' after language in "\.{->}"; command ignored} The
  7118. syntax of the output redirection command is ``\.{->$l$=\It{filename}}''.
  7119. \error{Improper \.@ within control text} Other than~\.{@>}, only~\.{@@} is
  7120. allowed within control text.
  7121. \error{Include file name not given} In an include command, the file name
  7122. must be on the same line as the \.{@i}.
  7123. \error{Incompatible section names} A section name is not uniquely
  7124. distinguishable from another.
  7125. \error{Infinite recursion in definition of environmental variable "\dots"}
  7126. Either a bug in your logic or in \WEB's.  If you think it's \WEB, please
  7127. report it.
  7128. \error{Input ended in mid-comment} A ``\.{/*}'' was not followed by a
  7129. matching~``\.{*/}''. 
  7130. \error{Input ended in middle of embedded comment} Embedded comments are
  7131. C-style comments within strings that are delimited by parentheses. (Certain
  7132. macros or \&{include} statements treat their arguments as strings.)
  7133. \error{Input ended in middle of string beginning with \.'\It{delimiter}\.'}
  7134. Found end-of-file before end of string.
  7135. \error{Input ended in section name} The closing \.{@>} of a section name
  7136. was not found.
  7137. \error{Input ended in verbatim comment}  A \atcmd{/*} was not followed by
  7138. a matching ``\.{*/}''.
  7139. \error{Inserted~'$c$' at beginning of continued string} The option~\.{-\\}
  7140. is in effect, but the continuation character~$c$ that ended the last line
  7141. does not appear as the first non-blank character on the present line.
  7142. \error{Invalid escape sequence \.'\.\\\It{c}\.' in ASCII
  7143. constant; null assumed} In a construction of the form \.{'\\\It{c}'},
  7144. $c$~was not one of~\.0, \.\\, \.', \.", \.?, \.a, \.b, \.f, \.n, \.r, \.t,
  7145. or~\.v.
  7146. \error{Name does not match} A section name was used that was never defined.
  7147. \error{Nested named modules.  Missing \.@?} A construction of the form
  7148. \atcmd{<\dots@>=} was found in the code section of a module. Perhaps the
  7149. equals sign is spurious or there's a missing \.{@\ } or~\.{@*}.
  7150. \error{Not present: \.<\It{section name}\.>} A section name of the form
  7151. \.{@<\dots@>} was referenced but never defined.
  7152. \error{Output file name not given} You must say \.{@o\ \It{filename}}.
  7153. \error{Output file name too long; allowed only $n$~characters} The file
  7154. name following an \.{@o}~command is too long.
  7155. \error{Section name didn't end} A new module command (\.{@\ } or~\.{@*})
  7156. was encountered in the middle of a section name beginning with~\.{@<}.
  7157. \error{Section name ended in mid-comment} An \.{@\ } or \.{@*} was
  7158. encountered while inside a comment beginning with~``\.{/*}''.
  7159. \error{Should use double \.@ within ASCII constant} You should say
  7160. `\atcmd{'@@'}'', not ``\.{@'@'}''.
  7161. \error{String beginning with \.'\It{delimiter}\.' didn't end} Quoted strings
  7162. must end on the same input line as they began, unless they are explicitly
  7163. continued by a backslash as the very last character in the line.
  7164. \error{TeX line had to be broken} \FTANGLE\ had to insert its own line
  7165. break in a \TeX\ input line.  Usually this will be done satisfactorily, but
  7166. it's best to check it out.
  7167. \error{Too many END DOs} Issued only when the \.{-d}~option is used and the
  7168. \&{do}\dots\&{end do} blocks don't match properly. \It{Note: This option is
  7169. obsolete; use \Ratfor\ instead.}
  7170. \error{Verbatim string didn't end} Verbatim strings (beginning with~\.{@=})
  7171. must end on the same line as they began. (They can't be continued with
  7172. backslashes.) 
  7173. \error{WARNING:  Code mode ended during unbracketed optional argument.
  7174. Should there be white space after language command?} If you say
  7175. ``\.{\dots|@ninteger i|\dots}, the '\.i'~is interpreted as a command-line
  7176. type of argument to~\.{@n}.  Leave a space after the~\.{@n}.
  7177. ^^)error messages!\>{FTANGLE})
  7178. \errorclass Errors related to preprocessing and macro processing.
  7179. ^^(error messages!macros(
  7180. \error{Actual number of macro arguments ($m$) does not match number of
  7181. def'n ($n$)} \WEB\ macros with a fixed number of arguments (not defined
  7182. with an ellipsis) must be called with precisely the same number of
  7183. arguments. Macros with a variable number of arguments must be called with
  7184. at least as many arguments as explicitly defined.
  7185. \error{Adjacent operators \."\It{name1}\ \It{name2}\." not allowed in
  7186. expression} For example, you can't say ``\.{A\ ||\ ||\ B}''.
  7187. \error{Argument \It{n} of \.{\_TRANSLIT} must be a string} The arguments of
  7188. this built-in must be enclosed in quotes.
  7189. \error{Argument \It{n} of \.{\_TRANSLIT} doesn't begin with \.{'\It{c}'}}
  7190. The delimiter characters for the string arguments of \.{\_TRANSLIT} must
  7191. all be the same.
  7192. \error{Auto insertion type must be one of \."ibfmps"} The characters
  7193. between brackets in \.{@m[\dots]} must be one of \.{ibfmps*}.
  7194. \error{Can't have \.{@\#elif} after \.{@\#else}} The order must be
  7195. \.{@\#if}\dots\.{@\#elif}\dots\.{@\#elif}\dots\.{@\#else}\dots\.{@\#endif}.
  7196. \error{Can't have more than 6 types of automatic insertion material;
  7197. remaining ignored} You would get this message if you said \.{@m[*f]\dots},
  7198. since the \.{*}~already counts as the six types \.{bifmps}.
  7199. \error{Can't negate type \It{name}} You can only apply the \.{!} operator
  7200. to numeric types.
  7201. \error{Can't take one's complement of type \It{name}; operand converted to
  7202. integer} You can only take the one's complement of an integer.
  7203. \error{\.{'defined'} ends prematurely} In \WEB\ macros, \.{defined} must be
  7204. followed by an identifier.
  7205. \error{\.{'defined'} must act on identifier, not type \It{name}} As above.
  7206. \error{Expected \.{')'} after ellipsis} Macros with variable numbers of
  7207. arguments must be defined with the format ``\.{@m\ A(x,y,...)\
  7208. \It{text}}''; no other arguments may follow the ellipsis.
  7209. \error{Expected constant after \."\.{\#:}\."} For automatic statement
  7210. labelling, you must say \.{\#:\It{n}}, where $n \ge 0$.
  7211. \error{Found space instead of ']' after automatic insertion material} The
  7212. syntax of an automatic insertion macro is \.{@m[\dots]\ \It{name}\ \It{text}}.
  7213. \error{Identifier \."\It{name}\." not allowed as binary operand} Possibly you
  7214. forgot to define a macro. For example, in \.{\_EVAL(A+B)}, both~\.A and~\.B
  7215. must be \WEB\ macros.
  7216. \error{Identifier must follow \.{\#!}; command ignored} In \WEB\ macro
  7217. text, the construction \.{\#!\It{name}} means substitute the macro
  7218. parameter \It{name} without expanding it.
  7219. \error{Identifier must follow \.{\#\&}} The construction \.{\#\&\It{name}}
  7220. is intended for internal use by the designer of \FWEB; do not use it.
  7221. \error{Identifier must follow \.{@\#undef}} You must say \atcmd{\#undef A},
  7222. where \.A~is a macro name.
  7223. \error{Ignored out-of-order \.{"\It{preprocessor cmd}"} (mlevel = \It{n})}
  7224. There's something wrong with a preprocessor construction. The order must be
  7225. \.{@\#if}\dots\.{@\#elif}\dots\.{@\#elif}\dots\.{@\#else}\dots\.{@\#endif}.
  7226. \error{Internal function name \."\It{name}\." not defined} Do not use the
  7227. construction \.{\#\&}; it's for internal use only.
  7228. \error{Invalid data type \It{name} in promotion} A crazy syntax error, or a
  7229. \error{Invalid operand of exponentiate has type \It{name}} There's
  7230. something wrong with an exponentiation operation (\.{\^}) in a macro
  7231. expression. 
  7232. \error{Invalid operand of unary minus has type \It{name}} The unary minus~(\.-)
  7233. can only be applied to numeric types.
  7234. \error{Invalid preprocessor block structure (level \It{n}).  Missing
  7235. \.{@\#endif}?} The definition section ended before an \.{@\#if} statement
  7236. was properly terminated. 
  7237. \error{Invalid type \It{name} in bit operation. (Macro not defined?)} You
  7238. can only apply bit operations such as \.\& or \.{||} to integers.
  7239. \error{Invalid statement number offset (\It{n}) after \.{\#:}; 1~assumed} In
  7240. the construction \.{\#:\It{n}}, $n$~must satisfy $n \ge 0$.
  7241. \error{Invalid token \.{0x\It{XX}} (\.{'\It{c}'}) after \.{\#}} In \WEB\
  7242. macro text, only the constructions \.{\#:} or \.{\#!} were expected here.
  7243. \error{Invalid token \.{'$c$'} (0x\It{XX}) in expression} There's a syntax
  7244. error in an argument to something like an \.{@\#if}.
  7245. \error{Invalid type returned from \_eval\_} There's something wrong with
  7246. the expression evaluator, or a syntax error in an expression.
  7247. \error{Macro after \.{\#!} may not have arguments} The more general case is
  7248. not implemented.
  7249. \error{Macro buffer full; \It{n} bytes requested for \It{reason}} The macro
  7250. expansion buffer overflowed. The size can be increased with the \.{-mb}
  7251. option. However, this message may also signify a bug in \FWEB.
  7252. \error{Macro definition may not start with \.{'$c$'}; \.{-m} option
  7253. ignored} There's trouble with a macro definition from the command line.
  7254. Macro names must begin with an alphabetic character, an underscore, or a
  7255. dollar sign. 
  7256. \error{Macro inner recursion depth exceeded} Either a macro was too
  7257. complicated, or a bug permitted an infinite recursion.
  7258. \error{Macro outer recursion depth exceeded} As above.
  7259. \error{Macro must start with identifier} There's something wrong with a
  7260. \WEB\ macro. 
  7261. \error{Macro token \.{"\#!"} must be followed by a parameter} In \WEB\
  7262. macro text, the construction \.{\#!}\It{name} means substitute the macro
  7263. parameter \It{name} without expanding it.
  7264. \error{Macro token \.{"\#*"} must be followed by a parameter} In \WEB\
  7265. macro text, the construction \.{\#*}\It{name} means stringize the macro
  7266. parameter \It{name} without expanding it, and without adding an extra level
  7267. of quotes if the parameter is already a quoted string.
  7268. \error{Missing argument to token-paste operation. Null assumed} The
  7269. operator~\.{\#\#} is not allowed at the very beginning or end of a macro
  7270. definition. 
  7271. \error{Missing equivalence field while undefining \."\It{name}\."; this
  7272. shouldn't happen!} There's trouble in paradise; a bug in \FWEB.
  7273. \error{Missing internal function name after \.{\#\&}} The construction
  7274. \.{\#\&}\It{name} is intended for internal use by the designer of \FWEB; do
  7275. not use it.
  7276. \error{Missing macro parameter in definition of macro \."\It{name}\.". Token
  7277. \dots\ is invalid; can only have identifiers and commas between (\dots)}
  7278. There's something wrong with the argument list of a \WEB\ macro definition.
  7279. \error{Missing right paren in definition of macro \."\It{name}\."} Parentheses
  7280. didn't match up while processing the argument list of a \WEB\ macro.
  7281. \error{Missing \.{'('} in call to macro \."\It{name}\."} This macro was defined
  7282. to have arguments, but is used without an argument list.
  7283. \error{No \.{')'} in call to macro \."\It{name}\."} In a call to a \WEB\ macro,
  7284. the closing parenthesis couldn't be found.
  7285. \error{Non-numeric type returned from eval (undefined macro?); assumed
  7286. FALSE} The expression evaluator couldn't reduce an expression to~0 or~1.
  7287. \error{Non-numeric type returned from neval (undefined macro?); assumed 0}
  7288. The expression evaluator couldn't reduce an expression to a number.
  7289. \error{Null expression encountered during expression evaluation; 0 assumed}
  7290. You would get this message, for example, if you said `\atcmd{\#if()}'.
  7291. \error{Only one \.{@\#else} allowed} Only one \.{@\#else} is permitted in
  7292. an \.{@\#if} construction. Perhaps you meant to say \.{@\#elif}.
  7293. \error{Overriding previous auto insertion type~$c$} Auto insertions for the
  7294. same type do not stack.  You said something like
  7295. \.{@m[f]} but type~\.f had already appeared in a previous such
  7296. construction (possibly implicitly, through a~'\.*').
  7297. \error{Right operand of \.{'$c$'} is zero} You can't divide by~0.
  7298. \error{Section ended during scan for \.{"@\#else"}, \.{"@\#elif"}, or
  7299. \.{"@\#endif"}. Inserted \.{"@\#endif"}. (elevel = \It{n})} A \.{@\ } or
  7300. \.{@*} was encountered before a \.{@\#if} was properly closed.
  7301. \error{Sorry, @\#pragma command not implemented yet} But you were clever to
  7302. \error{Too many macro arguments in definition of \."\It{name}\."; MAX\_MARGS =
  7303. \It{n}} A maximum of \\{MAX\_MARGS} arguments are allowed for \WEB\ macros.
  7304. \error{WARNING:  Command-line language~\It{language} overridden in limbo by
  7305. \It{language}} You specified a language on the command line, but a
  7306. different one in the file.  Generally, put the language command into the
  7307. file.
  7308. \error{WARNING: \."\It{name}\." is already undefined} You attempted to
  7309. \.{@\#undef} an identifier that was not defined as a \WEB\ macro.
  7310. ^^)error messages!macros)
  7311. \errorclass {\tt Ratfor} errors.
  7312. ^^(error messages!\>{Ratfor}(
  7313. An annoying class of error messages is that which begins with ``Output
  7314. ended \dots''. If an expected delimiter is missing, the scan will, at
  7315. present, proceed 
  7316. to the end of file. Really, it's possible to stop the scan before that, say
  7317. at the beginning of the next function; that mechanism will be installed in
  7318. future versions. 
  7319. \error{Automatic statement number out of bounds; \It{n} assumed} An
  7320. automatic statement number bigger than \Fortran's maximum of~99999 was
  7321. generated. 
  7322. \error{Case value \It{val} of type double truncated to int} Cases should
  7323. really be integer expressions.
  7324. \error{Can't return value from program or subroutine} The statement
  7325. ``\.{return \It{expr};}'' is allowed only in functions, not subroutines or
  7326. main programs.
  7327. \error{Expected identifier after \."\It{name}\."} There's a missing name after
  7328. \&{program}, \&{subroutine}, or \&{function}.
  7329. \error{Ignored \.{'\It{r}'} not matched with \.{'\It{l}'}} There were too
  7330. many right delimiters~$r$ to be matched with the left delimiter~$l$.
  7331. \error{Inserted \.{'\{'}} A compound statement was expected here.
  7332. \error{Inserted \.{'\It{c}'} after \."\It{name}\."} For example, \&{default}
  7333. wasn't followed by its mandatory colon.
  7334. \error{Invalid escape sequence '\.\\\It{letter}' in Ratfor character
  7335. constant; null assumed} In a construction of the form \.{'\\\It{c}'},
  7336. $c$~was not one of~\.0, \.\\, \.', \.", \.?, \.a, \.b, \.f, \.n, \.r, \.t,
  7337. or~\.v.
  7338. \error{Missing left paren after "\It{name}"; expansion aborted} Certain
  7339. keywords such as \&{while} are expected to be followed by a left
  7340. parenthesis.
  7341. \error{Missing opening delimiter \.{'\It{c}'}; text not copied} A
  7342. construction beginning with the character~\It{c} was expected here.
  7343. \error{Missing right brace (level \It{n}) at beginning of function; END
  7344. statement inserted} A \&{program}, \&{subroutine}, or \&{function}
  7345. statement was encountered before the body of a preceding program unit was
  7346. properly terminated with a right brace.
  7347. \error{Misplaced keyword: \."\It{name}\." must appear inside loop}
  7348. For example, \&{next} is allowed only inside loops such as~\&{for}.
  7349. \error{Misplaced keyword: \."\It{name}\." must be used only inside
  7350. \.{"switch"}} For example, \&{default} is allowed only inside a \&{switch}.
  7351. \error{Output ended after \.{'\{'}} End of file was encountered before a
  7352. matching right brace was found.
  7353. \error{Output ended at beginning of statement} A single or compound
  7354. statement was expected here.
  7355. \error{Output ended during scan of simple statement} A semicolon to
  7356. terminate the statement wasn't found.
  7357. \error{Output ended while copying to \.{'\It{r}'}} In some cases, \Ratfor\
  7358. copies things directly to the output while searching for a closing
  7359. delimiter. In this case, the closing delimiter wasn't found.
  7360. \error{Output ended while scanning for \.{'\It{c}'}} Some sort of list,
  7361. such as the argument to a \&{for} statement, wasn't properly terminated.
  7362. \error{Output ended while skipping newlines} Probably a statement was
  7363. expected here. Comments are also skipped while skipping over newlines.
  7364. \error{Ratfor character constant longer than one byte; extra characters
  7365. ignored} In \Ratfor, as in~C, single quotes denote character constants
  7366. whose length is one byte, so
  7367. constructions such as \.{'ab'} are not allowed. Perhaps you intended this
  7368. to be a character string, which should be enclosed by double quotes:
  7369. \.{"ab"}.
  7370. \error{Ratfor is not loaded\dots} You linked on the dummy package
  7371. \.{ratfor0.o} instead of \.{ratfor.o}.  Therefore, you're not allowed to
  7372. set the language to \\{RATFOR}.
  7373. \error{Shouldn't encounter top level here} There's something wrong with
  7374. \FWEB's stacking mechanism for expanding \Ratfor\ keywords.
  7375. \error{Unexpected keyword \."\It{name}\." ignored} For example, an \&{until}
  7376. was used without a preceding \&{repeat}.
  7377. ^^)error messages!\>{Ratfor})
  7378. \errorclass General messages from {\tt FWEAVE}.
  7379. ^^(error messages!\>{FWEAVE}(
  7380. \error{\.{@f}~line ends prematurely} For changing category codes, the
  7381. syntax is \.{@f\ `$a$\ \t{n}}.
  7382. \error{A string must follow~\.{@l}} Where is the text of the limbo text
  7383. definition? 
  7384. \error{Braces don't balance in comment} This holdover from Knuth's Pascal
  7385. \WEB\ is sometimes spurious, and should be improved.
  7386. \error{Can't have vertical bars in \.{@!}~compiler directives} A
  7387. restriction of the implementation.
  7388. \error{Category code must be between~0 and~15}  Just as in \TeX.
  7389. \error{Control codes are forbidden in control text} If you need an~\.{@},
  7390. you can say ``\.{\\AT!}''.
  7391. \error{Control text didn't end} The terminating \.{@>} must be on the same
  7392. line as the control text began.
  7393. \error{Double \.@ required outside of sections} If you intend for the
  7394. character~\.{'@'} to be here, you must double it. Otherwise, you're using a
  7395. control code that isn't allowed here.
  7396. \error{Double \.@ should be used in strings} No control codes are allowed
  7397. inside strings; for the '\.@'~symbol you must say~`\atcmd{@}'.
  7398. \error{Identifier was already explicitly defined via~\.{@[} in module~$n$} 
  7399. Identifiers should be explicitly defined in only one place.
  7400. \error{Illegal use of \.@ in comment} No control codes are allowed in
  7401. comments. If you intend the character~'\.@', you must double it.
  7402. \error{Implicit declaration of `\It{name}' conflicts with previous
  7403. declaration at module~$n$}  The syntax parser recognized a complete
  7404. function (during phase~2), but either the function name had already been
  7405. identified by an \.{@[}~command in phase~1 or the function has been defined
  7406. more than once.
  7407. \error{Improper format definition} There are too many or too few items in
  7408. an \.{@f} command.
  7409. \error{Improper macro definition: expected \.{')'} after ellipsis}
  7410. Self-explanatory. 
  7411. \error{Improper macro definition: expected identifier} Self-explanatory.
  7412. \error{Improper macro definition: unrecognized token in argument list}
  7413. Self-explanatory, but the message should be made more explicit.
  7414. \error{Input ended in mid-comment} A ``\.{/*}'' was not followed by a
  7415. matching~``\.{*/}''. 
  7416. \error{Input ended in middle of string beginning with '\It{delimiter}'}
  7417. Found end-of-file before end of string.
  7418. \error{Input ended in section name} The closing \.{@>} of a section name
  7419. was not found.
  7420. \error{Inserted~$c$ at beginning of continued string} The option~\.{-\\}
  7421. is in effect, but the continuation character~$c$ that ended the last line
  7422. does not appear as the first non-blank character on the present line.
  7423. \error{Invalid \.{@f} command:  One of the representation~\.{`a}, \.{`\\a},
  7424. or~\.{`\^\^M} is required} A left quote appears after~\.{@f} says that you
  7425. want to change a \TeX\ category code.  Use the same syntax for the
  7426. character whose catcode is to be changed as you would following \TeX's
  7427. \.{\\catcode} command.
  7428. \error{Invalid category code} A numerical constant was expected here.
  7429. \error{Invalid op code~$n$} There's something wrong with the operator being
  7430. processed.  If you can't figure this one out, please report it.
  7431. \error{Missing \.{'|'} after code text} Did you forget to switch out of
  7432. code mode in the middle of \TeX\ text?
  7433. \error{No op\_macro name for "\dots" [\It{language}]; token ignored}
  7434. There's something funny about an operator overload.  If you can't figure
  7435. this out, please report it.
  7436. \error{Operator after~\.{@v} is invalid} There's something wrong with the
  7437. operator after an \.{@v}~command.  Dot constants should be written
  7438. \It{sans} dots; characters such as parentheses are not valid operators. 
  7439. \error{Second argument (replacement text) of~\.{@v} must be a quoted
  7440. string} The syntax of an operator overload command is \.{@v\ \It{newop}\
  7441. "\It{string}"\ \It{oldop}}.
  7442. \error{Section ended in middle of Fortran-90 continuation} \WEB\ thinks the
  7443. last line was a continuation (ended by the continuation character~'\.\\'
  7444. or~'\.\&'), but then reached end-of-file.
  7445. \error{Section name didn't end} A new module command (\.{@\ } or~\.{@*})
  7446. was encountered in the middle of a section name beginning with~\.{@<}.
  7447. \error{String beginning with \.'\It{delimiter}\.' didn't end} Quoted strings
  7448. must end on the same input line as they began, unless they are explicitly
  7449. continued by a backslash as the very last character in the line.
  7450. \error{String must follow~\.{@l}} Limbo text commands have the form
  7451. `\atcmd{l\ "abc\\ndef"}'.
  7452. \error{TeX string should be in code text only} An \.{@t} command is misplaced.
  7453. \error{Verbatim string didn't end} Verbatim strings (beginning with~\.{@=})
  7454. must end on the same line as they began. (They can't be continued with
  7455. backslashes.) 
  7456. \error{You can't do that in code text} Commands like \.{@d} or \.{@f} are
  7457. not allowed here.
  7458. \error{You can't do that in TeX text} The following commands are not
  7459. allowed in \TeX\ text: \.{@,}, \.{@|}, \.{@/}, \.{@\#}, \.{@+}, \.{@\&},
  7460. \.{@;}, \.{@e}, \.{@:}.
  7461. \error{You need an \.= sign after the section name} Self-explanatory. One
  7462. sometimes gets this error if \FWEAVE\ has gotten confused about which part
  7463. of the section it's in.
  7464. \error{You should say \.{@@}} Don't forget to double the~\.{@}'s in \WEB\
  7465. source code.
  7466. \error{You should say \.{\\@@}} The single-character \TeX\ macro~\.{\\@}
  7467. must be written in \WEB\ source code as~\.{\\@@}.
  7468. ^^)error messages!\>{FWEAVE})
  7469. ^^)error messages)
  7470. \Knuth
  7471. \appendix K: GETTING {\tt WEB} ONTO a NEW COMPUTER.[INSTALLATION]
  7472. ^^[installation]
  7473. \endKnuth
  7474. \[The following paragraph, extracted from Knuth's original report,  is
  7475. included here mostly for entertainment.\] 
  7476. \KNUTH
  7477. ``If you have only the present report, not a tape, you will have to prepare
  7478. files \.{WEAVE.WEB} and \.{TANGLE.WEB} by hand, typing them into the
  7479. computer by following Appendices~D and~E. Then you have to simulate the
  7480. behavior of \.{TANGLE} by converting \.{TANGLE.WEB} manually into
  7481. \.{TANGLE.C}; with a good text editor this takes about six hours. Then
  7482. you have to correct errors that were made in all this hand work; but still
  7483. the whole project is not impossibly difficult, because in fact the entire
  7484. development of \.{WEAVE} and \.{TANGLE} (including the writing of the
  7485. programs and the manual) took less than two months of work.''
  7486. \It{[Note from J.~A. Krommes: {\rm(!!!)}]}
  7487. \endKNUTH
  7488. \input guide0 % Bring in the material from the reference guide.
  7489.